Let's say I have some JSON as below
response = {
"totalrecords": 2,
"data": [
{
"stateCd": "U.K",
"stateName": "uttarakhand",
"details": {
"id": [
"2312-k",
"2312-k"
],
"date": [
"10-OCT-2019",
"11-OCT-2019"
],
"icp": [
2233,
6443
],
"icpr": [
3.434,
23.232
]
}
},
{
"stateCd": "U.P",
"stateName": "uttar pradesh",
"details": {
"id": [
"2712-k",
"5412-k"
],
"date": [
"10-OCT-2019",
"11-OCT-2019"
],
"icp": [
2233,
6443
],
"icpr": [
32.434,
31.232
]
}
}
]
}
I wanted to convert it into data frame as below

but while trying to convert it into dataframe using pandas.json_normalize()
I am unable to reach my desired output
what I have tried:
data_trunc=response['data'] # to extract data from response
pd.json_normalize(data_trunc)

pd.json_normalize(data_trunc,record_path=['details','id'],meta=['stateCd','stateName'])

but this don't include date, icp, icpr columns
so I have tried different permutation and combination
pd.json_normalize(data_trunc,record_path=[['details','id'],['date']],meta=['stateCd','stateName'])
pd.json_normalize(data_trunc,record_path=[['details','id'],['details'.'date']],meta=['stateCd','stateName'])
but landed up to same error TypeError: unhashable type: 'list'
response = {...}is not actually JSON, it is a Pythondict, which looks like JSON when formatted like this. (although that's okay here, aspandas.json_normalize()does takedictinput)