Reputation: 78402
wowee...and the python with json is what? I get the below string from poping a redis queue that was generated by dumping a dictionary into a json string and placing in a list. when I pop..wow..I get the below
args = {'series': 'exr|usd|gbp', 'K': 2, 'M': 2, 'tau': 1}
args = json.loads(args)
Traceback (most recent call last):
File "/home/ubuntu/workspace/chaos/chaos_worker.py", line 12, in <module>
args = json.loads(args)
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 1 (char 1)
Upvotes: 1
Views: 5323
Reputation: 5108
Wait, are you converting a python dict into json? In that case use json.dumps
. The args
as you have defined on first line is in fact a dict
.
args = {'series': 'exr|usd|gbp', 'K': 2, 'M': 2, 'tau': 1}
print args.__class__
Out: dict
args = json.dumps(args)
print args
Out: '{"series": "exr|usd|gbp", "K": 2, "M": 2, "tau": 1}'
In json parsable string as expected.
Upvotes: 4