Created
April 1, 2015 22:28
-
-
Save themiurgo/75a9485fa17e6e54d686 to your computer and use it in GitHub Desktop.
Paste for NDJSON documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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