Skip to content

Instantly share code, notes, and snippets.

@subho007
Created November 10, 2016 14:04
Show Gist options
  • Save subho007/90cf90b1662143b65dc3345841547cf9 to your computer and use it in GitHub Desktop.
Save subho007/90cf90b1662143b65dc3345841547cf9 to your computer and use it in GitHub Desktop.
Json dump to CSV
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