Python Read Json File And Convert To CSV

January 30, 2018
import json
# import csv
import unicodecsv as csv

with open('input.json') as data_file:
    data = json.loads(data_file.read())

with open('output.csv', 'wb') as csv_file:
    writer = csv.writer(csv_file, encoding='utf-8')

    writer.writerow(['id', 'date', 'name'])

    for row in data:
        item_id = row['id']
        created = row['created']
        name = row['title']

        row = [item_id, created, name]

        writer.writerow(row)

NOTE: to support unicode in CSV, you need unicodecsv

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.