How to parse JSON Array of objects in python
How to parse JSON Array of objects in python
Take a look at the json module. More specifically the Decoding JSON: section.
import json
import requests
response = requests.get() # api call
users = json.loads(response.text)
for user in users:
print(user[id])
You can try like below to get the values from json response:
import json
content=[{
username: admin,
first_name: ,
last_name: ,
roles: system_admin system_user,
locale: en,
delete_at: 0,
update_at: 1511335509393,
create_at: 1511335500662,
auth_service: ,
email: [email protected],
auth_data: ,
position: ,
nickname: ,
id: pbjds5wmsp8cxr993nmc6ozodh
}, {
username: chatops,
first_name: ,
last_name: ,
roles: system_user,
locale: en,
delete_at: 0,
update_at: 1511335743479,
create_at: 1511335743393,
auth_service: ,
email: [email protected],
auth_data: ,
position: ,
nickname: ,
id: akxdddp5p7fjirxq7whhntq1nr
}]
for item in content:
print(Name: {}nEmail: {}nID: {}n.format(item[username],item[email],item[id]))
Output:
Name: admin
Email: [email protected]
ID: pbjds5wmsp8cxr993nmc6ozodh
Name: chatops
Email: [email protected]
ID: akxdddp5p7fjirxq7whhntq1nr
How to parse JSON Array of objects in python
It seems what you are looking for is the json module. with it you can use this to parse a string into json format:
import json
output=json.loads(myJsonString)