List of nested JSON

Now, if the data is a list of nested JSONs, we will get multiple records in our dataframe.

Python3




data = [
    {
        'id': '001',
        'company': 'XYZ pvt ltd',
        'location': 'London',
        'info': {
            'president': 'Rakesh Kapoor',
            'contacts': {
                    'email': 'contact@xyz.com',
                    'tel': '9876543210'
            }
        }
    },
    {
        'id': '002',
        'company': 'PQR Associates',
        'location': 'Abu Dhabi',
        'info': {
            'president': 'Neelam Subramaniyam',
            'contacts': {
                    'email': 'contact@pqr.com',
                    'tel': '8876443210'
            }
        }
    }
]
  
pd.json_normalize(data)


Output:

json data converted to pandas dataframe

So, in the case of multiple levels of JSON, we can try out different values of max_level attribute.

Converting nested JSON structures to Pandas DataFrames

In this article, we are going to see how to convert nested JSON structures to Pandas DataFrames.

Similar Reads

JSON with multiple levels

In this case, the nested JSON data contains another JSON object as the value for some of its attributes. This makes the data multi-level and we need to flatten it as per the project requirements for better readability, as explained below....

List of nested JSON

...

JSON with nested lists

...