Sorry in advance that this was such a newbie question. I'm just starting to write python, and I got confused that you are changing values ββfrom nested dictionaries / lists, so I appreciate any help!
I have json example data:
{ "scans": [ { "status": "completed", "starttime": "20150803T000000", "id":533}, { "status": "completed", "starttime": "20150803T000000", "id":539} ] }
I would like to infer "id" from the "scan" key.
def listscans(): response = requests.get(scansurl + "scans", headers=headers, verify=False) json_data = json.loads(response.text) print json.dumps(json_data['scans']['id'], indent=2)
doesn't seem to work because the nested key / values ββare inside the list. those.
>>> print json.dumps(json_data['scans']['id']) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list indices must be integers, not str
Can someone point me in the right direction to make this work? my long-term goal is to create a for loop that puts the entire id in another dictionary or list that I can use for another function.
source share