With Python, I'm saving json documents onto separate lines like this:
from bson import json_util # pymongo
with open('test.json', 'ab') as f:
for document in documents:
f.write(json_util.dumps(document)+'\n')
and then reading like this:
with open('test.json') as f:
for line in f:
document = json_util.loads(line)
The ease and simplicity make me think that there must be a gotcha? Is this all there is to linejson, aka jsonlines?
ndjson Newline Delimited JSON NDJSON is a convenient format for storing or streaming structured data that may be processed one record at a time. It works well with unix-style text processing tools and shell pipelines.
Yes, that's all there is to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With