Home > Software design >  Access a json field in python
Access a json field in python

Time:05-11

Im using a get request in python

x = requests.get(url, headers = ... ) 
print(x.json())

and the result im getting is

{
'organization': {
'id': '6', 
'name': 'TestPostman', 
'displayName': 'TestPostman', 
'canHaveGateways': True, 
'maxGatewayCount': 0, 
'maxDeviceCount': 0
},
'createdAt': '2022-05-10T18:07:49.327175Z', 
'updatedAt': '2022-05-10T19:44:09.667978Z'
}

How can i access any of the organization's fields ? I tried x.organizzation['id'] but does not work .

CodePudding user response:

If you want to access the ID in the Organization try this:

x = x.json()
print(x["organization"]["id"])
  • Related