I have the following json:
{
"meta": {
"collection": 0
},
"series": {
"default": {
"data": {
"columns": [
{
"columnName": "A",
"columnType": "STRING"
},
{
"columnName": "B",
"columnType": "STRING"
}
],
"rows": [
[
{
"columnName": "A",
"value": "X1"
},
{
"columnName": "B",
"value": "Y1"
}
],
[
{
"columnName": "A",
"value": "X2"
},
{
"columnName": "B",
"value": "Y2"
}
]
]
}
}
}
}
I'm trying to parse this json into a dataframe which should look like this:
A B
--------
X1 Y1
X2 Y2
Here's what I have tried so far:
import pandas as pd
results = {"meta":{"collection":0},"series":{"default":{"data":{"columns":[{"columnName":"A","columnType":"STRING"},{"columnName":"B","columnType":"STRING"}],"rows":[[{"columnName":"A","value":"X1"},{"columnName":"B","value":"Y1"}],[{"columnName":"A","value":"X2"},{"columnName":"B","value":"Y2"}]]}}}}
s = results["series"]["default"]["data"]
df = pd.json_normalize(s, record_path=["rows"])
The problem is the columns in the df contain the json array, and not the values
0 1
0 {'columnName': 'A', 'value': 'X1'} {'columnName': 'B', 'value': 'Y1'}
1 {'columnName': 'A', 'value': 'X2'} {'columnName': 'B', 'value': 'Y2'}
Is there anyway to use json_normalize to achieve the result I want, or is parsing through json myself the way to go?