I am writing a program, which requires me to generate a very large json
file. I know the traditional way is to dump a dictionary list using json.dump()
You could also assume you have an iterable it
that you want to write out to a file handle fh
as a large JSON array of records, and do the following, which I think is the most straightforward approach:
def write_json_iter(it, fh):
print("[", file=fh)
for n, rec in enumerate(it):
if n > 0:
print(",", file=fh)
json.dump(rec, fh)
print("]", file=fh)