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?
Aucun commentaire:
Enregistrer un commentaire