Get JSON response in Python, but in original JavaScript format









up vote
0
down vote

favorite












I am putting a JSON response into a variable via requests.json() like this:



response = requests.get(some_url, params=some_params).json()


This however converts JSON's original " to Python's ', true to True, null to None.



This poses a problem when trying to save the response as text and the convert it back to JSON - sure, I can use .replace() for all conversions mentioned above, but even once I do that, I get other funny json decoder errors.



Is there any way in Python to get JSON response and keep original JavaScript format?










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am putting a JSON response into a variable via requests.json() like this:



    response = requests.get(some_url, params=some_params).json()


    This however converts JSON's original " to Python's ', true to True, null to None.



    This poses a problem when trying to save the response as text and the convert it back to JSON - sure, I can use .replace() for all conversions mentioned above, but even once I do that, I get other funny json decoder errors.



    Is there any way in Python to get JSON response and keep original JavaScript format?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am putting a JSON response into a variable via requests.json() like this:



      response = requests.get(some_url, params=some_params).json()


      This however converts JSON's original " to Python's ', true to True, null to None.



      This poses a problem when trying to save the response as text and the convert it back to JSON - sure, I can use .replace() for all conversions mentioned above, but even once I do that, I get other funny json decoder errors.



      Is there any way in Python to get JSON response and keep original JavaScript format?










      share|improve this question













      I am putting a JSON response into a variable via requests.json() like this:



      response = requests.get(some_url, params=some_params).json()


      This however converts JSON's original " to Python's ', true to True, null to None.



      This poses a problem when trying to save the response as text and the convert it back to JSON - sure, I can use .replace() for all conversions mentioned above, but even once I do that, I get other funny json decoder errors.



      Is there any way in Python to get JSON response and keep original JavaScript format?







      python json python-requests






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 18 hours ago









      barciewicz

      42039




      42039






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          json() is the JSON decoder method. You are looking at a Python object, that is why it looks like Python.



          Other formats are listed on the same page, starting from Response Content




          • .text: text - it has no separate link/paragraph, it is right under "Response Content"


          • .content: binary, as bytes


          • .json(): decoded JSON, as Python object


          • .raw: streamed bytes (so you can get parts of content as it comes)

          You need .text for getting text, including JSON data.






          share|improve this answer




















          • Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
            – spectras
            18 hours ago

















          up vote
          1
          down vote













          You can get the raw text of your response with requests.get(some_url, params=some_params).text



          It is the json method which converts to a Python friendly format.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223975%2fget-json-response-in-python-but-in-original-javascript-format%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            json() is the JSON decoder method. You are looking at a Python object, that is why it looks like Python.



            Other formats are listed on the same page, starting from Response Content




            • .text: text - it has no separate link/paragraph, it is right under "Response Content"


            • .content: binary, as bytes


            • .json(): decoded JSON, as Python object


            • .raw: streamed bytes (so you can get parts of content as it comes)

            You need .text for getting text, including JSON data.






            share|improve this answer




















            • Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
              – spectras
              18 hours ago














            up vote
            1
            down vote



            accepted










            json() is the JSON decoder method. You are looking at a Python object, that is why it looks like Python.



            Other formats are listed on the same page, starting from Response Content




            • .text: text - it has no separate link/paragraph, it is right under "Response Content"


            • .content: binary, as bytes


            • .json(): decoded JSON, as Python object


            • .raw: streamed bytes (so you can get parts of content as it comes)

            You need .text for getting text, including JSON data.






            share|improve this answer




















            • Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
              – spectras
              18 hours ago












            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            json() is the JSON decoder method. You are looking at a Python object, that is why it looks like Python.



            Other formats are listed on the same page, starting from Response Content




            • .text: text - it has no separate link/paragraph, it is right under "Response Content"


            • .content: binary, as bytes


            • .json(): decoded JSON, as Python object


            • .raw: streamed bytes (so you can get parts of content as it comes)

            You need .text for getting text, including JSON data.






            share|improve this answer












            json() is the JSON decoder method. You are looking at a Python object, that is why it looks like Python.



            Other formats are listed on the same page, starting from Response Content




            • .text: text - it has no separate link/paragraph, it is right under "Response Content"


            • .content: binary, as bytes


            • .json(): decoded JSON, as Python object


            • .raw: streamed bytes (so you can get parts of content as it comes)

            You need .text for getting text, including JSON data.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 18 hours ago









            tevemadar

            3,9102622




            3,9102622











            • Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
              – spectras
              18 hours ago
















            • Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
              – spectras
              18 hours ago















            Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
            – spectras
            18 hours ago




            Another option would be serializing the object again. That would ensure it is valid and they all have the samef formatting. That means they wouldn't be saved verbatim though. Depends on use case.
            – spectras
            18 hours ago












            up vote
            1
            down vote













            You can get the raw text of your response with requests.get(some_url, params=some_params).text



            It is the json method which converts to a Python friendly format.






            share|improve this answer
























              up vote
              1
              down vote













              You can get the raw text of your response with requests.get(some_url, params=some_params).text



              It is the json method which converts to a Python friendly format.






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                You can get the raw text of your response with requests.get(some_url, params=some_params).text



                It is the json method which converts to a Python friendly format.






                share|improve this answer












                You can get the raw text of your response with requests.get(some_url, params=some_params).text



                It is the json method which converts to a Python friendly format.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 18 hours ago









                Reupiey

                1396




                1396



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223975%2fget-json-response-in-python-but-in-original-javascript-format%23new-answer', 'question_page');

                    );

                    Post as a guest














































































                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20