i querying postgres server data , particular json object gets returned string. tried following not giving correct output: (it's ipython outputs)
test out[103]: '{"max"=>28, "min"=>18, "custom"=>[{"id"=>"12345","name"=>"test_pur"}]}' in[104]: test.replace("=>",":") out[104]: '{"max":28, "min":18, "custom":[{"id":"12345", "name":"test_pur"}]}' in[105]: j_obj = json.dumps(test) in[106]: j_obj out[106]: '"{\\"max\\"=>28, \\"min\\"=>18, \\"custom\\"=>[{\\"id\\"=>\\"12345\\", \\"name\\"=>\\"test_pur\\"}]}"' how can convert string json recognizing ":" symbol?
when trying "json.loads" . following errors:
traceback (most recent call last): file "/library/python/2.7/site-packages/ipython/core/interactiveshell.py", line 3035, in run_code exec(code_obj, self.user_global_ns, self.user_ns) file "", line 1, in data = json.loads(temp) 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 : delimiter: line 1 column 11 (char 10)
try json.loads() load (deserialize) json string python dict:
>>> import json >>> s = '{"max":28, "min":18, "custom":[{"id":"12345", "name":"test_pur"}]}' >>> data = json.loads(s) >>> print data["max"] 28
Comments
Post a Comment