Goal: Iterate over a sub-json looking in 2 keys for a specific string
In PHP it's easy but for python 3, I cannot seems to find a proper way. I tried other solutions I found on the web but I always end up getting an error.
Example JSON:
{
"main1": {
"sub1": {
"prop1": "name1",
"prop2": "name2"
},
"sub2": {
"prop1": "name1",
"prop2": "name2"
},
},
"main2": {
"sub1": {
"prop1": "name1",
"prop2": "name2"
},
"sub2": {
"prop1": "name1",
"prop2": "name2"
},
},
}
Code
self.data = dataIO.load_json('data/data.json')
for item in self.data['main1'].items():
if item['prop1'] == 'name1' or item['prop2'] == 'name1':
print 'found one'
Error:
TypeError: string indices must be integers