Python > parsing JSON

Given:

j='{ "key": "value", "array": [ { "key": 1 }, { "key": 2, "dictionary": { "a": "Apple", "b": "Butterfly", "c": "Cat", "d": "Dog" } }, { "key": 3 } ]}'

Note: [] are for lists, {} are for dictionaries.

We can parse it with Python like this:

import json
jp=json.loads(j)
print jp["key"]
value


print jp["array"][0]["key"]
1

 

https://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file

 

Leave a Reply

Your email address will not be published. Required fields are marked *