JSON (unlike JavaScript or Python) only allows double-quoted strings.
>>> print json.loads('["hi","bye"]')
[u'hi', u'bye']
>>> print json.loads("['hi','bye']")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Because of this, and because Python tends to prefer single-quoted strings, the repr()
of a Python object is almost always invalid JSON. You must use json.dumps()
instead.
>>> v = ["hi", "bye"]
>>> repr(v)
"['hi', 'bye']"
>>> json.dumps(v)
'["hi", "bye"]'