【发布时间】:2020-05-26 02:25:43
【问题描述】:
我有一个包含数十万行的 JSON 响应,并且全部从字典 python 解析并使用 json.load 转换为 JSON
现在收到无效响应的 JSON 响应,因此解决方法如下
回复
{
"ComplianceType": "",
"Details": {
"InstalledTime": "",
"PatchBaselineId": "",
"PatchState": ""
},
"ExecutionSummary": {
"ExecutionId": "",
"ExecutionTime": "",
"ExecutionType": ""
},
"Id": "",
"ResourceId": "",
"ResourceType": "",
"Severity": "",
"Status": "",
"Title": ""
}
{
"ComplianceType": "",
"Details": {
"InstalledTime": "",
"PatchBaselineId": "",
"PatchState": ""
},
"ExecutionSummary": {
"ExecutionId": "",
"ExecutionTime": "",
"ExecutionType": ""
},
"Id": "",
"ResourceId": "",
"ResourceType": "",
"Severity": "",
"Status": "",
"Title": ""
}
解决方法使其有效
[{
"ComplianceType": "",
"Details": {
"InstalledTime": "",
"PatchBaselineId": "",
"PatchState": ""
},
"ExecutionSummary": {
"ExecutionId": "",
"ExecutionTime": "",
"ExecutionType": ""
},
"Id": "",
"ResourceId": "",
"ResourceType": "",
"Severity": "",
"Status": "",
"Title": ""
},
{
"ComplianceType": "",
"Details": {
"InstalledTime": "",
"PatchBaselineId": "",
"PatchState": ""
},
"ExecutionSummary": {
"ExecutionId": "",
"ExecutionTime": "",
"ExecutionType": ""
},
"Id": "",
"ResourceId": "",
"ResourceType": "",
"Severity": "",
"Status": "",
"Title": ""
}
]
这些我需要通过程序来完成,当我尝试使用 sed shell --> #sed -i 's#}#},#' test.json
[{
"ComplianceType": "",
"Details": {
"InstalledTime": "",
"PatchBaselineId": "",
"PatchState": ""
},,
"ExecutionSummary": {
"ExecutionId": "",
"ExecutionTime": "",
"ExecutionType": ""
},,
"Id": "",
"ResourceId": "",
"ResourceType": "",
"Severity": "",
"Status": "",
"Title": ""
},
{
"ComplianceType": "",
"Details": {
"InstalledTime": "",
"PatchBaselineId": "",
"PatchState": ""
},,
"ExecutionSummary": {
"ExecutionId": "",
"ExecutionTime": "",
"ExecutionType": ""
},,
"Id": "",
"ResourceId": "",
"ResourceType": "",
"Severity": "",
"Status": "",
"Title": ""
},
]
请提供适用于 shell 或 python 的解决方法
【问题讨论】: