Skip to content

Instantly share code, notes, and snippets.

@sreevardhanreddi
Created March 8, 2019 11:12
Show Gist options
  • Save sreevardhanreddi/4712639b198e488cea6221e28189cce7 to your computer and use it in GitHub Desktop.
Save sreevardhanreddi/4712639b198e488cea6221e28189cce7 to your computer and use it in GitHub Desktop.
list_of_dicts = [
{ "prop": 1, "attr": 2 },
{ "prop": 3, "attr": 4 }
# ...
]
with open(filepath, 'w') as f:
f.write('[')
for obj in list_of_dicts[:-1]:
json.dump(obj, f)
f.write(',')
json.dump(list_of_dicts[-1], f)
f.write(']')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment