If you load in the entire json as a dict (or list) e.g. using json.load, you can use json_normalize:

In [11]: d = {"response": {"body": {"contact": {"email": "mr@abc.com", "mobile_number": "0123456789"}, "personal": {"last_name": "Muster", "gender": "m", "first_name": "Max", "dob": "1985-12-23", "family_status": "single", "title": "Dr."}, "customer": {"verified": "true", "customer_id": "1234567"}}, "token": "dsfgf", "version": "1.1"}}

In [12]: df = pd.json_normalize(d)

In [13]: df.columns = df.columns.map(lambda x: x.split(".")[-1])

In [14]: df
Out[14]:
        email mobile_number customer_id verified         dob family_status first_name gender last_name title  token version
0  mr@abc.com    0123456789     1234567     true  1985-12-23        single        Max      m    Muster   Dr.  dsfgf     1.1
Answer from Andy Hayden on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › converting nested json to data frame
r/learnpython on Reddit: Converting nested JSON to data frame
February 4, 2022 -

I'm trying to figure out how to extract heavily nested JSON data and convert it to data tables using pandas. I got to where I can go down to one nested level, but I don't know how to phrase the request to go to the next level down.

import pandas

URL = 'https://statsapi.mlb.com/api/v1.1/game/642186/feed/live'

df = pandas.read_json(URL)

df=pandas.json_normalize(df['liveData'])

df=pandas.DataFrame(df)

print(df)
print(df.info())

So this goes to the 'liveData' level. Nested under 'liveData' is 'plays' -- 'allPlays' -- 'result'. Is it possible to write the JSON_normalize code so it gets down to the 'result' level, and the data frame is at the result level (which I would use sqlalchemy to put into a MySQL table)?

Advise to turn a nested JSON dynamically into db tables Dec 11, 2025
r/dataengineering
8mo ago
Turning JSON arrays into tables - Data flattening Apr 14, 2022
r/dataengineering
4y ago
How to unnest a json recursively Oct 23, 2023
r/dataengineering
2y ago
Converting JSON to .csv file Oct 1, 2025
r/learnpython
11mo ago
Beginner working with Json in Pandas. Nov 30, 2015
r/learnpython
10y ago
More results from reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › converting-nested-json-structures-to-pandas-dataframes
Converting nested JSON structures to Pandas DataFrames - GeeksforGeeks
November 22, 2021 - To convert it to a dataframe we will use the json_normalize() function of the pandas library. ... Here, we see that the data is flattened and converted to columns. If we do not wish to completely flatten the data, we can use the max_level attribute ...
Discussions

pandas - How to convert nested json into python dataframe - Stack Overflow
I want to convert my nested json format into pandas dataframe i have tried but my data is something looking like this which is not correct I have tried to fetch the json and save inside the innings More on stackoverflow.com
🌐 stackoverflow.com
python - How to convert a nested JSON file into a Pandas dataframe? - Stack Overflow
I'm trying to convert a nested JSON in a dataframe using Python. However, all the solutions applied missed some part of the JSON file. In particular, I tried to use the function "_json_normalize& More on stackoverflow.com
🌐 stackoverflow.com
November 3, 2022
python - Nested Json in to dataframe (pandas) - Stack Overflow
I`m importing the following json. It is not super extensive but I just added a small piece here for demonstration: {'request': {'Target': 'Offer', 'Format': 'json', 'Service': 'XXXXX', 'Versi... More on stackoverflow.com
🌐 stackoverflow.com
python - Parsing nested JSON into dataframe - Stack Overflow
I am trying to parse a JSON string to its lowest granularity to a panda dataframe. ... But a large chunk of the data is still nested under networkRank. More on stackoverflow.com
🌐 stackoverflow.com
April 19, 2016
Top answer
1 of 3
70

If you load in the entire json as a dict (or list) e.g. using json.load, you can use json_normalize:

In [11]: d = {"response": {"body": {"contact": {"email": "mr@abc.com", "mobile_number": "0123456789"}, "personal": {"last_name": "Muster", "gender": "m", "first_name": "Max", "dob": "1985-12-23", "family_status": "single", "title": "Dr."}, "customer": {"verified": "true", "customer_id": "1234567"}}, "token": "dsfgf", "version": "1.1"}}

In [12]: df = pd.json_normalize(d)

In [13]: df.columns = df.columns.map(lambda x: x.split(".")[-1])

In [14]: df
Out[14]:
        email mobile_number customer_id verified         dob family_status first_name gender last_name title  token version
0  mr@abc.com    0123456789     1234567     true  1985-12-23        single        Max      m    Muster   Dr.  dsfgf     1.1
2 of 3
2

It's much easier if you deserialize the JSON using the built-in json module first (instead of pd.read_json()) and then flatten it using pd.json_normalize().

# deserialize
with open(r'C:\scoring_model\json.js', 'r') as f:
    data = json.load(f)

# flatten
df = pd.json_normalize(d)

If a dictionary is passed to json_normalize(), it's flattened into a single row, but if a list is passed to it, it's flattened into multiple rows. So if the nested structure contains only key-value pairs, pd.json_normalize() with no parameters suffices to flatten it.


However, if the data contains a list (JSON array in the nesting in the file), then passing record_path= argument to let pandas find the path to the records. For example, if the data is like the following (notice how the value under "body" is a list, i.e. a list of records):

data = {
    "response":[
        {
            "version":"1.1",
            "customer": {"id": "1234567", "verified":"true"},
            "body":[
                {"email":"mr@abc.com", "mobile_number":"0123456789"},
                {"email":"ms@abc.com", "mobile_number":"9876543210"}
            ]
        }, 
        {
            "version":"1.2",
            "customer": {"id": "0987654", "verified":"true"},
            "body":[
                {"email":"master@abc.com", "mobile_number":"9999999999"}
            ]
        }
    ]
}

then you can pass record_path= to let the program know that the records are under "body" and pass meta= to set the path to the metadata. Note how in "body", "version" and "customer" are in the same level in the data but "id" is nested one level more so you need to pass a list to get the value under "id".

df = pd.json_normalize(data['response'], record_path=['body'], meta=['version', ['customer', 'id']])

🌐
Paul Apivat
paulapivat.com › technical_notes › example_tech › python_create_df_from_nested_json
Create DataFrames from Nested JSON data | Paul Apivat
# empty lists name_list_24 = [] address_list_24 = [] circle_id_list_24 = [] discord_username_list_24 = [] profile_address_24 = [] # loop through level 1 for dct in df_manifest_24['circle.users'][0]: name_list_24.append(dct['name']) address_list_24.append(dct['address']) circle_id_list_24.append(dct['circle_id']) # conditionally loop through level 2 # use try-except for dct in df_manifest_24['circle.users'][0]: try: for k, v in dct['profile'].items(): if k == 'discord_username': discord_username_list_24.append(v) elif k == 'address': profile_address_24.append(v) else: print("Done.") except: AttributeError pass # create dataframe from lists df_24 = pd.DataFrame(list(zip(name_list_24, address_list_24, circle_id_list_24)), columns=['Name', 'Address', 'Circle_Id'])
🌐
Medium
medium.com › swlh › converting-nested-json-structures-to-pandas-dataframes-e8106c59976e
Converting nested JSON structures to Pandas DataFrames | by Derek | The Startup | Medium
July 7, 2020 - APIs and document databases sometimes return nested JSON objects and you’re trying to promote some of those nested keys into column headers but loading the data into pandas gives you something like this: df = pd.DataFrame.from_records(results["issues"], columns=["key", "fields"])
🌐
Medium
avithekkc.medium.com › how-to-convert-nested-json-into-a-pandas-dataframe-9e8779914a24
How to convert nested JSON into a Pandas DataFrame | by Avi Patel | Medium
August 17, 2021 - Fetching a value from a nested JSON object. This article will introduce how to convert JSON to a Pandas DataFrame and how to deal with the above mentioned common problems using just a simple pandas function - “json_normalize()”
🌐
KDnuggets
kdnuggets.com › how-to-convert-json-data-into-a-dataframe-with-pandas
How to Convert JSON Data into a DataFrame with Pandas - KDnuggets
The json_normalize() function from the Pandas library is a better way to manage nested JSON data. It automatically flattens the nested structure of the JSON data, creating a DataFrame from the resulting data.
Find elsewhere
🌐
Hackers and Slackers
hackersandslackers.com › json-into-pandas-dataframes
Turn JSON into Pandas DataFrames - Hackers And Slackers
June 19, 2026 - Well, we could write our own function, but because pandas is amazing, it already has a built in tool that takes care of this for us. ... Yep – it's that easy. pandas takes our nested JSON object, flattens it out, and turns it into a DataFrame.
🌐
DataCamp
campus.datacamp.com › courses › reshaping-data-with-pandas › advanced-reshaping
Reading nested data into a DataFrame | Python
These are more complex data to work with. For those cases, we can use the json_normalize function from pandas. It takes our nested JSON object, flattens it out, and reads it into a DataFrame.
🌐
Kaggle
kaggle.com › code › jboysen › quick-tutorial-flatten-nested-json-in-pandas
Quick Tutorial: Flatten Nested JSON in Pandas | Kaggle
September 27, 2017 - Explore and run AI code with Kaggle Notebooks | Using data from NY Philharmonic Performance History
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-nested-json-to-pandas-dataframe-with-specific-format
How to Convert Nested JSON to Pandas DataFrame with Specific Format | Saturn Cloud Blog
May 1, 2026 - DataFrames can be created from a variety of data sources, including CSV files, SQL databases, and JSON files. To convert a nested JSON file into a Pandas DataFrame, we will use the json_normalize() function from the pandas.io.json module.
🌐
Stack Overflow
stackoverflow.com › questions › 74304278 › how-to-convert-a-nested-json-file-into-a-pandas-dataframe
python - How to convert a nested JSON file into a Pandas dataframe? - Stack Overflow
November 3, 2022 - import json import pandas as pd # Import json file with open("file.json") as f: data = json.load(f) df = pd.json_normalize(data) # Cleanup df["refactorings"] = df["refactorings"].apply(lambda x: x[0] if x else {}) # Flatten the column df["refactorings"] = df.apply(lambda x: func(x["refactorings"], {}), axis=1) # For each row, flatten nested dict, make a dataframe of it # and concat it with non nested columns # Then, concat all new dataframes new_df = pd.concat( [ pd.concat( [ pd.DataFrame(df.loc[idx, :]).T.drop(columns="refactorings"), pd.DataFrame(df.loc[idx, "refactorings"], index=[idx]), ], axis=1, ).fillna(method="ffill") for idx in df.index ] ).reset_index(drop=True)
🌐
GitConnected
levelup.gitconnected.com › a-deep-dive-into-nested-json-to-data-frame-with-python-69bdabb41938
A Deep Dive into Nested JSON to Data Frame with Python | by Renu Khandelwal | Level Up Coding
August 6, 2023 - However, the simplicity of JSON belies the complexity it can contain, with API responses varying greatly, encompassing a vast array of data and metadata. In this blog, you will learn how to convert simple and nested JSON structures into data frames and write these data frames into a CSV file for seamless data management and analysis, along with error handling.
🌐
Plain English
plainenglish.io › home › blog › python › data extraction: parse a 3-nested json object and convert it to a pandas dataframe
Data Extraction: Parse a 3-Nested JSON Object and Convert it to a pandas dataframe
June 6, 2021 - Now that we have a dictionary in each row of the datatable dt, we can use pandas.Series to convert the dictionaries to a Pandas series format and apply** pandas.Dataframe** to further convert it into type dataframe. ... “Data extraction through API requests and web scraping is especially useful for analyzing or automating data service on web-based applications.” · The JSON format is already compatible in itself and pandas functions add extra flexibility in making the parsing and readability of this data more user-friendly.
Top answer
1 of 3
4

This function recursively calls itself to flatten dictionaries and lists.

from collections import OrderedDict

def flatten(json_object, container=None, name=''):
    if container is None:
        container = OrderedDict()
    if isinstance(json_object, dict):
        for key in json_object:
            flatten(json_object[key], container=container, name=name + key + '_')
    elif isinstance(json_object, list):
        for n, item in enumerate(json_object, 1):
            flatten(item, container=container, name=name + str(n) + '_')
    else:
        container[str(name[:-1])] = str(json_object)
    return container

Examples:

flatten([1, 2, 3])
OrderedDict([('1', '1'), ('2', '2'), ('3', '3')])

flatten([1, 2, 3], name='x')
OrderedDict([('x1', '1'), ('x2', '2'), ('x3', '3')])

flatten({'a': [1, 2, 3], 'b': 4, 'c': {'d': [5, 6], 'e': 7}}, name='x')
OrderedDict([('xa_1', '1'),
             ('xa_2', '2'),
             ('xa_3', '3'),
             ('xc_e', '7'),
             ('xc_d_1', '5'),
             ('xc_d_2', '6'),
             ('xb', '4')])

Response:

# j = json string
>>> pd.DataFrame(flatten(j), index=[0]).T
                                                      0
perMinuteLimit                                       10
distance                                             10
perMonthCurrent                                       0
longitude                                     35.751607
perMonthLimit                                      2000
latitude                                      -6.162959
perMinuteCurrent                                      0
networkRank_1_networkId                            6402
networkRank_1_type3G_sampleSizeSpeed                 29
networkRank_1_type3G_averageRssiAsu        9.5429091136
networkRank_1_type3G_pingTime                  320.9600
networkRank_1_type3G_networkType                      3
networkRank_1_type3G_averageRssiDb    -69.5664329624972
networkRank_1_type3G_networkName                Vodacom
networkRank_1_type3G_networkId                     6402
networkRank_1_type3G_downloadSpeed            1508.1304
networkRank_1_type3G_uploadSpeed               893.7692
networkRank_1_type3G_reliability      0.804236452826138
networkRank_1_type3G_sampleSizeRSSI                 948
networkRank_1_networkName                       Vodacom
networkRank_2_networkId                            6400
networkRank_2_type3G_sampleSizeSpeed                 21
networkRank_2_type3G_averageRssiAsu       15.3537142857
networkRank_2_type3G_pingTime                  259.0000
networkRank_2_type3G_networkType                      3
networkRank_2_type3G_averageRssiDb    -61.4563389583101
networkRank_2_type3G_networkName                   tiGO
networkRank_2_type3G_networkId                     6400
networkRank_2_type3G_downloadSpeed             516.0000
networkRank_2_type3G_uploadSpeed               320.4211
networkRank_2_type3G_reliability      0.911904765537807
networkRank_2_type3G_sampleSizeRSSI                 935
networkRank_2_networkName                          tiGO
networkRank_3_networkId                            6403
networkRank_3_type3G_sampleSizeSpeed                 21
networkRank_3_type3G_averageRssiAsu       13.2729999375
networkRank_3_type3G_pingTime                  194.5556
networkRank_3_type3G_networkType                      3
networkRank_3_type3G_averageRssiDb    -58.1521092977699
networkRank_3_type3G_networkName                 Airtel
networkRank_3_type3G_networkId                     6403
networkRank_3_type3G_downloadSpeed            1080.2500
networkRank_3_type3G_uploadSpeed               572.1579
networkRank_3_type3G_reliability      0.554680264185345
networkRank_3_type3G_sampleSizeRSSI                 587
networkRank_3_networkName                        Airtel
network_type                                       None
apiVersion                                            2
2 of 3
0

1) Parse JSON string to python structure

2) Iterete over 'networkRank' list of dictionaries and put each key you want to add inside the hash

for data_row in deserialized_json['networkRank']:
    data_row['latitude'] = deserialized_json['latitude']
    # etc

3)

yourdataframe = pd.DataFrame( deserialized_json['networkRank'] )
🌐
Stack Overflow
stackoverflow.com › questions › 57194293 › turning-nested-json-with-arrays-into-dataframe-in-python
Turning Nested JSON with Arrays into DataFrame in Python - Stack Overflow
I would like to turn the below JSON response into a table under "steps" I could just extract "name" and "options" and there values
🌐
Edureka Community
edureka.co › home › community › categories › python › read nested json as dataframe
Read Nested Json as DataFrame | Edureka Community
July 25, 2019 - Hi, I have a nested json and want to read as a dataframe. I tried multiple options but the data is not coming into ... -+----------+------+-----+