Question
Is there a way to read sequentially pretty-printed JSON objects in Python?
Suppose you have a JSON file like this:
{
"a": 0
}
{
"a": 1
}
It's not JSONL, because each object takes more than one line. But it's not a single valid JSON object either. It's sequentially listed pretty-printed JSON objects.
json.loads
in Python gives an error about invalid formatting if you attempt to load this, and the documentation indicates it only loads a single object. But tools like jq
can read this kind of data without issue.
Is there some reasonable way to work with data formatted like this using the core json library? I have an issue where I have some complex objects and while just formatting the data as JSONL works, for readability it would be better to store the data like this. I can wrap everything in a list to make it a single JSON object, but that has downsides like requiring reading the whole file in at once.
There's a similar question here, but despite the title the data there isn't JSON at all.