close

How to parse JSON Array of objects in python

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to parse JSON Array of objects in python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to parse JSON Array of objects in python?

  1. How to parse JSON Array of objects in python?

    Take a look at the json module. More specifically the 'Decoding JSON:' section.

  2. parse JSON Array of objects in python

    Take a look at the json module. More specifically the 'Decoding JSON:' section.

Method 1

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'])

Method 2

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

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read