Created
November 10, 2016 14:04
-
-
Save subho007/90cf90b1662143b65dc3345841547cf9 to your computer and use it in GitHub Desktop.
Json dump to CSV
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 json | |
import csv | |
_file = "apps" | |
list_length = 50000 | |
contents = open("%s.json" % _file).read() | |
contents = json.loads(contents)["RECORDS"] | |
i = 0 | |
contents_list = [ | |
contents[x:x+list_length] for x in range(0, len(contents), list_length)] | |
for contents in contents_list: | |
with open('%s-%d.csv' % (_file, i), 'w') as f: | |
content = contents[0] | |
w = csv.DictWriter(f, content.keys()) | |
w.writeheader() | |
for content in contents: | |
w.writerow(content) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment