I have JSON file (list.json) as an input:
"Module1": {
"Description": "",
"Layer": "1",
},
"Vendor": ""
},
"Module2": {
"Description": "",
"Layer": "2",
},
"Vendor": ""
},
"Module3": {
"Description": "",
"Layer": "3",
},
"Vendor": ""
},
"Module1": 4
"Description": "",
"Layer": "4",
},
"Vendor": ""
},
I am trying to extract all modules (their names) if "Vendor" matches to some criteria, in this case all of the modules with "Vendor": "comp" should be printed (Module2, Module3).
My code is: import json
list_components = []
with open (/list.json) as f:
swc_list = json.load(f)
for i in swc_list:
if i['Vendor'] == 'comp':
list_components.append(i)
print (list_components)
When I run this code, I keep getting: string indices must be integers on line if i['Vendor'] == 'comp':
What would be the best approach to do this?