I have a nested json that I am trying to flatten:
[
{
"name": "table1",
"count": 123,
"columns": {
"col1": "string",
"col2": "string"
},
"partitions": 2
},
{
"name": "table2",
"count": 234,
"columns": {
"col3": "int",
"col4": "string",
"col5": "int"
},
"partitions": 4
}
]
I am trying to flatten this into something like below:
name count col_name col_type partitions
table1 123 col1 string 2
table1 123 col2 string 2
table2 234 col3 int 4
table2 234 col4 string 4
table2 234 col5 int 4
Reading json into pandas dataframe.
with open("file.json") as datafile:
data = json.load(datafile)
dataframe = pd.DataFrame(data)
pd.json_normalize doesn't work since I wouldn't like to create too many columns.
Rather I am trying to create more rows.
Could someone guide me as to how can I best achieve this in python or using pandas?
Appreciate any help. Thanks.