- Code: Select all
test ='[{"a":"1","b":"2"},{"c":"5","d":"6"}]'
jst = json.loads(test)
jst
[{u'a': u'1', u'b': u'2'}, {u'c': u'5', u'd': u'6'}]
works
the following does not work:
- Code: Select all
test ="[{'a':'1','b':'2'},{'c':'5','d':'6'}]"
jst = json.loads(test)
gives
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 365, 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 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 3 (char 2)
difference is in the quotes.. I have a file that has single quotes in the data
Any idea? is there parameter to flip the quotes in json?