I have a json object
sample_json ={
"workspaces": [
{
"wsid": "1",
"wsname": "firstworkspace",
"report":[{"reportname":"r1ws1"},{"reportname":"r2ws1"},{"reportname":"r1ws1"}]
},
{
"wsid": "2",
"wsname": "secondworkspace",
"report":[{"reportname":"r1ws2"},{"reportname":"r2ws2"},{"reportname":"r1ws2"}]
}
]}
I want to flatten/normalize the json so that it looks like this :
I can flatten each level using the pandas function "json_normalize" e.g Level 1
import pandas as pd
df1 = pd.json_normalize(sample_json, record_path=['workspaces'])
df1
e.g Level 2
import pandas as pd
df_api = pd.json_normalize(sample_json, record_path=['workspaces','report'])
df_api
I have read quiet a few articles such as this one but I am struggling to understand how to include information from the two levels (workspaces and reports) in a single dataframe. Any advice or help would be appreciated. Copy to sample data in a google colab notebook is here


