New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json.loads errors out on valid JSON #65381
Comments
Run the following Python JSON parsing script on valid JSON: import json
json.loads( '["[\"Residential | Furniture | Cabinets\",\"119.99\"]"]' ) Result: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python33\lib\json\__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "C:\Python33\lib\json\decoder.py", line 352, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python33\lib\json\decoder.py", line 368, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 1 column 5 (char 4) |
It is not a valid JSON. You may want to validate it against http://jsonlint.com/ What you have inside the string (single quotes) is the JSON representation but not the string representation which json.loads is supposed to parse. |
You need to escape backslashes inside a Python string literal or use raw-string literals: >>> import json
>>> json.loads(r'["[\"Residential | Furniture | Cabinets\",\"119.99\"]"]')
[u'["Residential | Furniture | Cabinets","119.99"]'] If the backslashes are unintentional then you could remove them: >>> json.loads('[["Residential | Furniture | Cabinets","119.99"]]')
[[u'Residential | Furniture | Cabinets', u'119.99']] Note: the result is different |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: