I want to iterate through a JSON response to match specific key value pair to print it and another value in the same list.
The JSON looks like
[
{
"status": "ok",
"slot": null,
"name": "blah",
"index": 0,
"identify": "off",
"details": null,
"speed": null,
"temperature": null
},
{
"status": "ok",
"slot": null,
"name": "blah1",
"index": 0,
"identify": "off",
"details": null,
"speed": null,
"temperature": null
},
{
"status": "ok",
"slot": null,
"name": "blah2",
"index": 1,
"identify": "off",
"details": null,
"speed": null,
"temperature": null
}
]
The code i tried so far:
url = http://something
data = json.loads(r.get(url, headers=headers, verify=False).content.decode('UTF-8'))
for value in data:
if value['name'] == 'blah' or 'blah1':
print(value)
And i tried with a next gen:
match = next(d for d in data if d['name'] == 'blah')
yield next(match)
But none of this worked.
The desired output i want is: If the 'name'='blah'
or 'name'='blah1'
, i want to print out name and the associated status with it.
'name'='blah'
'status'='ok'
'name'='blah1'
'status'='ok'
How can i do it with Python?