I have a scenario where I am trying to compare list elements with a json file and if there is a match then return certain values and create a json response. here are my json data
[
{
"evi": 1223,
"evn": "testapp1",
"conf": {
"c_gr": "tot",
"c_id": "112"
}
},
{
"evi": 6759,
"evn": "testapp2",
"conf": {
"c_gr": "tot",
"c_id": "112"
}
},
{
"evi": 3352,
"evn": "testapp3",
"conf": {
"c_gr": "tot7",
"c_id": "112"
}
}
]
Here is what I have tried so far :
response=requests.post('https://testaapp.com', headers=headers, data=data)
resp_json=response.json()
if response.status_code == 200:
print ('working fine...!!')
else:
print ('notworking !!')
metadata=resp_json['data']
m_list=[1123, 123445, 61887, 3352, 35811488976]
final_lst_data1 = []
final_lst_data2 = []
for key in m_list:
temp1= key
for keya in metadata:
if temp1 in metadata[keya]['evi']:
final_lst_data1.append(metadata['evn']) #return the names
final_lst_data2.append(metadata['evn'], metadata['conf']) #return evn and conf values after checking and then dump it to json from list in same json format if not possible then convert to json from list, not sure how to do this here.
But this doesnt works as it gives me below error
if key in metadata[keya]['evi']:
TypeError: list indices must be integers or slices, not dict
for keya in range(len(metadata))got this errorTypeError: argument of type 'int' is not iterable