Query JSON Parts

367
1
Jump to solution
12-10-2020 10:57 PM
DeanHowell1
Occasional Contributor III

I have a python script that is getting the machine details for a portal using the following code:

response = urllib.urlopen(portalUrl+'/portaladmin/machines?f=json&token='+token).read()
jsonResponse = json.loads(response)

the jsonResponse is as follows when I print jsonResponse['machines']: 

[{u'adminURL': u'https://10.10.24.94:7443/arcgis', u'machineName': u'10.10.24.94', u'role': u'standby'}, {u'adminURL': u'https://10.10.25.110:7443/arcgis', u'machineName': u'10.10.25.110', u'role': u'primary'}]

 

How do I create variables to get output separated into  machineName1,role1 and machineName2, role2?

Thanks 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DeanHowell1
Occasional Contributor III

I answered my own question but thought I would post the answer for completeness

 

response = urllib.urlopen(portalUrl+'/portaladmin/machines?f=json&token='+token).read()
jsonResponse = json.loads(response)

machineOneName = jsonResponse['machines'][0]['machineName']
machineTwoName = jsonResponse['machines'][1]['machineName']
machineOneRole = jsonResponse['machines'][0]['role']
machineTwoRole = jsonResponse['machines'][1]['role']

print (machineOneName, machineOneRole)

View solution in original post

0 Kudos
1 Reply
DeanHowell1
Occasional Contributor III

I answered my own question but thought I would post the answer for completeness

 

response = urllib.urlopen(portalUrl+'/portaladmin/machines?f=json&token='+token).read()
jsonResponse = json.loads(response)

machineOneName = jsonResponse['machines'][0]['machineName']
machineTwoName = jsonResponse['machines'][1]['machineName']
machineOneRole = jsonResponse['machines'][0]['role']
machineTwoRole = jsonResponse['machines'][1]['role']

print (machineOneName, machineOneRole)

0 Kudos