-1

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 .

haduki
  • 1,145
  • 5
  • 23
  • 1
    Does this answer your question? [Convert JSON string to dict using Python](https://stackoverflow.com/questions/4528099/convert-json-string-to-dict-using-python) – Kenny May 11 '22 at 09:41
  • I couldnt figure out the correct syntax. thanks a lot now it works – haduki May 11 '22 at 09:59

1 Answers1

4

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

x = x.json()
print(x["organization"]["id"])
alanturing
  • 214
  • 1
  • 8