Created
April 19, 2016 04:00
-
-
Save SIRHAMY/0d0c112118a8e07f8a5ca367bf6cd587 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 json | |
#This is going to fetch our lines one-by-one | |
#Useful for super-huge files | |
class JSONFetcher(): | |
def __init__(self, fileName): | |
self.fileName = fileName + '.json' | |
def fetch(self): | |
print("fetching...") | |
with open(self.fileName, 'rb') as f: | |
for line in f: | |
yield json.loads(line) | |
if __name__ == "__main__": | |
filename = "MY_FILENAME" | |
sourcefile = JSONFetcher(filename) | |
outfile = open("OUTFILE", 'wb') | |
for record in sourcefile.fetch(): | |
record['ADDED_KEY'] = "NEW_VALUE_HERE"] | |
jsonOut = json.dumps(record) | |
outfile.write(jsonOut + '\n') | |
outfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment