我正试图通过在pandas中找到的JSON_normalize函数对从API接收到的JSON进行规范化:
{
"cmd": {
"success": true,
"params": {
"count": 37,
"result": [
{
"id": "5f11c47fb2157c65ba029d4a",
"orgId": "5d0a54c6b2157c522d409098",
"name": "tag test",
"desc": "Removes unnecessary tags",
"eventType": "campaign.thing",
"status": "new",
"ts": "2020-07-17T15:32:15.894Z",
"summary": {
"ready": 0,
"inProgress": 0,
"success": 0,
"failure": 0,
"retry": 0
},
"emailUpdates": {},
"templateGroup": "Tags",
"templateName": "Tag_Removal",
"templateId": "5e84f5127094416efc422f67",
"createdBy": "tester",
"createdOn": "2020-07-17T15:32:15.894Z"
},
{
"id": "5f11c414b2157c65ba016b35",
"orgId": "5d0a54c6b2157c522d409098",
"name": "tag update",
"eventType": "campaign.thing",
"status": "new",
"ts": "2020-07-17T15:30:28.139Z",
"summary": {
"ready": 0,
"inProgress": 0,
"success": 0,
"failure": 0,
"retry": 0
},
"emailUpdates": {},
"templateGroup": "Tags",
"templateName": "Tag_Add",
"templateId": "5e84f2fe7094416efc3dd0cd",
"createdBy": "tester",
"createdOn": "2020-07-17T15:30:28.139Z"
},
...display another 35 JSON objects
]
}
}
}
收到回复后,我尝试通过下面的python行规范化代码:
df_norm = pd.json_normalize(data=Response_JSON, record_path='cmd')
我的输出不是我想要的,因为我最终生成了如下所示的数据帧大小(1,3):
(1,3)单元格包含文本形式的JSON的其余部分。我正在寻找的所需输出将是进一步深入JSON的列。例如,cmd.params.result.id和JSON对象的包含id
看来我的JSON的格式不允许它进一步深入。JSON Normalize Documentation有一个meta和record_path参数,但我没有成功地让它工作。任何帮助都将不胜感激
对于2个测试对象,可以使用以下方法访问嵌套级别:
…使用
print(df_norm.to_string())
打印以下内容:相关问题 更多 >
编程相关推荐