MJN All Blog Cheatsheets Elasticsearch GCP JS LinuxBash Misc Notes Other ShortcutKeys / - Search

Home / Other / Python / Convert JSON File to CSV


Convert JSON File to CSV

import csv, json, sys

input = open(sys.argv[1])
data = json.load(input)
input.close()

output = csv.writer(sys.stdout)

output.writerow(data[0].keys()) # header row

for row in data:
   output.writerow(row.values())

This page was generated by GitHub Pages. Page last modified: 20/09/07 11:03