So I have a Python code which returns a JSON string like this one:
'{"X": "value1", "Y": "value2", "Z": [{"A": "value3", "B": "value4"}]}'
What I want to do is to print and/or return (in Python) "value 3"
in order to use it. Also assign it to a variable so I can work with it later on.
How can I do this?
>>> 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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With