So I have a Python code which returns a JSON string like this one:
\'{"X": "value1", "Y": "value2", "Z": [{&
>>> import json
>>> a = json.loads('{"X":"value1","Y":"value2","Z":[{"A":"value3","B":"value4"}]}')
>>> a
{'Y': 'value2', 'X': 'value1', 'Z': [{'A': 'value3', 'B': 'value4'}]}
>>> a["Z"][0]["A"]
'value3'
OK, I assume your JSON looks like this (note the "
around each value
):
{"X":"value1", "Y":"value2", "Z":[{"A":"value3", "B":"value4"}]}
Then you can do this:
import json
j = '{"X":"value1", "Y":"value2", "Z":[{"A":"value3", "B":"value4"}]}'
k = json.loads(j)
assert k["Z"][0]["A"] == "value3"
Edit: Even simplejson
can't decode your original input.
>>> import simplejson
>>> s1 = '{"X":value1,"Y":"value2","Z":[{"A":"value3","B":value4}]}'
>>> simplejson.loads(s1)
simplejson.decoder.JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
>>> s2 = '{"X":"value1", "Y":"value2", "Z":[{"A":"value3", "B":"value4"}]}'
>>> print simplejson.loads(s2)["Z"][0]["A"]
value3