Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@almet
Last active December 15, 2016 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almet/04a151035de8a082770b6eaff4060621 to your computer and use it in GitHub Desktop.
Save almet/04a151035de8a082770b6eaff4060621 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import unicodecsv as csv
import sys
import json
def json_to_csv(source, destination):
loaded_json = json.load(source)['data']
writer = csv.writer(destination)
# First row contains the titles
keys = loaded_json[0].keys()
writer.writerow(keys)
for item in loaded_json:
values = [item[k] for k in keys]
writer.writerow(values)
if __name__ == '__main__':
json_to_csv(sys.stdin, sys.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment