I am really struggling with a search of a dict in python. What I do is call an external API using the Requests package.
response = requests.get(apiurl + vnendpoint + '?page=1&per_page=0&sort=id&api_key=' + apikey)
records = response.json()
This works fine and returns the following dict:
{u'pagination': {u'per_page': 0, u'total': 187, u'page': 1}, u'data': [{u'status': u'Inactive', u'name': u'access-a37', id': u'2', u'peripheral':...
The problem is, I now want to search the data object, which is a list inside the original JSON, for an ID which may or may not be there.
x = "1"
if x in records:
print("add")
This is the part I cannot get past. It always returns a false response, but I know the ID is there.
Am I missing something really straight forward here?
Thanks
dictnot the list. You have to access the list first. Then, you will need to check theidfield in the dicts I side that list.