Skip to content

Instantly share code, notes, and snippets.

@themiurgo
Created April 1, 2015 22:28
Show Gist options
  • Save themiurgo/75a9485fa17e6e54d686 to your computer and use it in GitHub Desktop.
Save themiurgo/75a9485fa17e6e54d686 to your computer and use it in GitHub Desktop.
Paste for NDJSON documents
import sys
import json
import itertools
fnames = sys.argv[1:]
jsons = [(json.loads(i) for i in open(fname)) for fname in fnames]
def paste(iterables):
for docs in itertools.izip_longest(*iterables, fillvalue={}):
for other in docs[1:]:
docs[0].update(other)
yield docs[0]
for doc in paste(jsons):
print json.dumps(doc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment