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?
python json python-requests
add a comment |
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?
python json python-requests
add a comment |
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?
python json python-requests
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
python json python-requests
asked 18 hours ago
barciewicz
42039
42039
add a comment |
add a comment |
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.
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
add a comment |
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.
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 18 hours ago
Reupiey
1396
1396
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password