Last active
December 15, 2016 13:32
-
-
Save almet/04a151035de8a082770b6eaff4060621 to your computer and use it in GitHub Desktop.
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
# -*- 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) |
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
unicodecsv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment