Skip to content

Instantly share code, notes, and snippets.

@KentaKudo
Created February 2, 2019 22:33
Show Gist options
  • Save KentaKudo/b1225c971a2f14cef5d4eb2177818cfe to your computer and use it in GitHub Desktop.
Save KentaKudo/b1225c971a2f14cef5d4eb2177818cfe to your computer and use it in GitHub Desktop.
An example to parse json into csv format in Python
import json # https://docs.python-guide.org/scenarios/json/
import csv # https://docs.python.org/3/library/csv.html
json_string = '[\
{"gender": "Male", "Nationality": "JPN", "document_type": "passport"}\
]'
parsed_json = json.loads(json_string)
with open('out.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for row in parsed_json:
writer.writerow(row.values())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment