我是python的新手。试图解析嵌套的json并转换为csv。尝试了其他解决方案(例如Dictwriter等)中提供的各种解决方案,但只能获取数据的最后记录。 json结构是动态的,即无法指定深度。我正在寻找一种不对任何变量进行硬编码的通用解决方案。
下面是示例数据
{
"documentType": "Rec",
"filters": [
{
"name": "pc",
"type": "string",
"size": 50,
"allowedValues": null,
"isCus": false,
"pre": null,
"fdn": "Unique Name",
"scale": null
},
{
"name": "Ss",
"type": "string",
"size": 50,
"allowedValues": null,
"isCus": false,
"precision": null,
"fdn": "Status String",
"scale": null
}
],
"selections": [
{
"name": "R.notify",
"type": "boolean",
"size": null,
"allowedValues": null,
"isCus": false,
"precision": null,
"fdn": "Notify",
"scale": null
},
{
"name": "intit",
"type": "string",
"size": 255,
"allowedValues": null,
"isCus": false,
"precision": null,
"fdn": "Initialization",
"scale": null
}
]
}
预期产量
"documentType","","name","type","size","allowedValues","isCus","precision","pre","fdn","scale"
"Rec","filters","pc","string","50","null","False","","null","Unique Name","null"
"","","Ss","string","50","null","False","null","","Status String","null"
"","selections","R.notify","boolean","null","null","False","null","","Notify","null"
"","","intit","string","255","null","False","null","","Initialization","null"