I currently have JSON available like this. There are 800 objects stored in one file called test.json
but the format isn't valid. I have showed 2 objects out of 800 below:
{
"_id": {
"$oid": "592638e163690a5c1f8f73e2"
},
"title": "simplifying fractions",
"url": "some_url",
"difficulty": "easy",
"webview": "",
"id": 0
} {
"_id": {
"$oid": "592638e163690a5c1f8f73f5"
},
"title": "patterns overlap",
"url": "some_url",
"difficulty": "hard",
"webview": "",
"id": 1
}
When I run the above two json objects through jsonlint.com
I am getting an error at line 10 saying there is a parse error. I want to convert it into something like this which is working in jsonlint.com
:
{
"0": {
"_id": {
"$oid": "592638e163690a5c1f8f73e2"
},
"title": "simplifying fractions",
"url": "some_url",
"difficulty": "easy",
"webview": "",
"id": 0
},
"1": {
"_id": {
"$oid": "592638e163690a5c1f8f73f5"
},
"title": "patterns overlap",
"url": "some_url",
"difficulty": "hard",
"webview": "",
"id": 1
}
}
Now in the above version it passes the lint. In the first version I simply have 800 JSON objects and I want to convert it into the version above where we have one big dictionary at the top and then a key like "0"
, "1"
followed by the JSON object. I am not sure how to start in creating the python script. Can someone give me a hint or some starting code on how I can parse the very first invalid JSON code?