0

My question is the same as this one here but no answer was accepted, I am looking to load a nested JSON file into python. The data looks like this:

{"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"}}

The answer from the previous question throws an extra data error. How can I import it?

Tim Pietzcker
  • 297,146
  • 54
  • 452
  • 522
prmlmu
  • 475
  • 1
  • 4
  • 12

1 Answers1

0

The question you linked contains valid JSON, while your JSON is not valid, because it basically looks like this:

{}
{}
{}

whereas a valid version of it would look like this:

[
{},
{},
{}
]

If your JSON is line sparated, you'll need to use some sort of third party library like https://jsonlines.readthedocs.io/en/latest/

Or, if the individual valid JSON blocks are in one line, you could just read the file line by line.

The other alternative would be to make sure that your JSON is actually valid.

Mike Scotty
  • 8,981
  • 5
  • 28
  • 42