Manipulating Python Json Dictionaries
I am trying to manipulate some JSON in python but I am getting really stuck. I can work with basic dictionaries in python but not this. I am trying to pull out individual variable
Solution 1:
if you look at the format you'll see it's actually a list containing dictionaries.
try:
print json.loads(data)['example'][0]['id']
Solution 2:
You could try as well jsontree
>>>mytree = jsontree()>>>mytree.something.there = 4>>>mytree['something']['there'] == 5>>>False>>>mytree['something']['there'] == 4>>>True
Solution 3:
Since "example" is a list of json : If you want to access id or other keys
print json.loads(data)['example'][0]['id']
print json.loads(data)['example'][0]['text'] ...
If you want to access keys inside options :
print json.loads(data)['example'][0]['options'][0]['firstop']
Post a Comment for "Manipulating Python Json Dictionaries"