Cale Sweeney Cale Sweeney -4 years ago 150
JSON Question

Accessing a json object nested in a json array with Python 3.x

Given the json payload below, how do I get the value of 'hotspot' using Python 3.x? The top level seems to be a a dict with one key value pair. 'Recs' is the key and the value is a Python list. I have loaded the json payload into the Python class using

json.loads(payload)
.

json payload:

{
'Recs': [{
'eSrc': 'big-a1',
'reqPs': {
'srcIP': '11.111.11.111'
},
'a1': {
'a1Ver': '1.0',
'obj': {
'eTag': '38f028e',
'sz': 1217,
'seq': '02391D2',
'hotspot': 'web/acme/srv/dev/8dd'
},
'confId': 'acme-contains',
'pipe': {
'name': 'acme.dev',
'oId': {
'pId': 'BDAD'
}
}
}
}]
}

Answer Source

{ indicates a dict, [ indicates a list so hotspot is at:

my_json['Recs'][0]['a1']['obj']['hotspot']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download