Last active
April 9, 2019 17:02
-
-
Save rbk/18a0bab6036e4eed4307505a5567e861 to your computer and use it in GitHub Desktop.
Json to CSV
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 sys | |
import json | |
input_file = sys.argv[len(sys.argv)-1] | |
print('INPUT: ', input_file) | |
output_file = input_file + '.csv' | |
data = json.loads(open(input_file).read()) | |
# print(",".join(list(data[0].keys()))) | |
csv_headers = ",".join(list(data[0].keys())) | |
with open(output_file, 'w') as f: | |
f.write(csv_headers + '\n') | |
for obj in data: | |
line = "" | |
values = [] | |
for key in obj: | |
values.append(str(obj[key])) | |
line = ",".join(values) | |
# print(line) | |
f.write(line + '\n') | |
print(output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment