我的问题与this one here相同,但是没有答案被接受,我正在寻找将嵌套的JSON文件加载到python中的方法。数据如下:
{"company_number":"09155805","data":
{"etag":"4b7fa3c10d6022ccf76d5b4266365a1ed41bb6da","kind":"persons-with-
significant-control-statement","links":{"self":"/company/09155805/persons-
with-significant-control-
statements/6EzwgguAevT_xs4JZq91pkUOvSw"},"notified_on":"2016-07-
31","statement":"psc-details-not-confirmed"}}
{"company_number":"NI603905","data":
{"etag":"f799cfaccc8642ff39b48031d59a5bc884c20b51","kind":"persons-with-
significant-control-statement","links":{"self":"/company/NI603905/persons-
with-significant-control-
statements/OwgKYSF7ZCvrG7JCilW00zRsg3g"},"notified_on":"2016-07-
28","statement":"no-individual-or-entity-with-signficant-control"}}
{"company_number":"05894872","data":
{"etag":"2805e15088bb7117208b57aa490673801c3cde8c","kind":"persons-with-
significant-control-statement","links":{"self":"/company/05894872/persons-
with-significant-control-statements/CPKer2m8uYG5Vh4NLKTzsf-
n10A"},"notified_on":"2016-08-03","statement":"no-individual-or-entity-with-
signficant-control"}}
上一个问题的答案引发了额外的数据错误。如何导入?
答案 0 :(得分:0)
您链接的问题包含有效的JSON,而您的JSON无效,因为它基本上是这样的:
{}
{}
{}
有效版本如下:
[
{},
{},
{}
]
如果您的JSON是行间距的,则需要使用某种第三方库,例如https://jsonlines.readthedocs.io/en/latest/
或者,如果单个有效的JSON块位于一行中,则可以逐行读取文件。
另一种选择是确保您的JSON实际上是有效的。