What is the difrence between:
-
s1 = '["a"]' -
s2 = "['a']"
When I do json.loads, I get following error for s2 but s1 is fine:
>>> s1='["a2"]'
>>> s2="['a2']"
>>> json.loads(s1)
[u'a2']
>>> json.loads(s2)
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
The problem is JSON uses double quotes (
") for quoting values, not single ones (').Which means the exception is thrown because of invalid JSON:
['a']["a"]Also the correct example is below, different than yours:
EDIT: I have updated the question with the correct output OP must have seen instead of what he/she posted (
json.loads('["a2"]')was not throwing errors,json.loads("['a2']")was).