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:
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.