Hello I want to extract the value of all pr1 from location1 & 2 from below json - Any ideas would be appreciated
import json
jsonget = {
"data":[
{
"location1":[
{
"pr1":"hn1",
"pr2":"2019-08-07"
}
]
},
{
"location2":[
{
"pr1":"hn2",
"pr2":"2019-08-07"
}
]
}
]
}
if __name__ == '__main__':
jsonout = json.dumps(jsonget)
jsonout1 = json.loads(jsonout)
for val in jsonout1['data']:
print val['location1'] Error:==ERROR:
[{u'pr1'Traceback (most recent call last):
print val['location1']
KeyError: 'location1'
: u'hn1', u'pr2': u'2019-08-07'}]
[Finished in 0.1s with exit code 1]
