Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert JSON object array to CSV File
import json
import csv
# Read JSON File
with open('users.json') as json_file:
data = json.load(json_file)
user_data = data['users']
# Prepare CSV file
data_file = open('users.csv', 'w')
# Make CSV file writer
csv_writer = csv.writer(data_file)
count = 0
for tmp in user_data:
if count == 0:
# Add headers to CSV file
header = tmp.keys()
count += 1
# Write data to CSV file
# Close the CSV file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment