Skip to content

Instantly share code, notes, and snippets.

Embed
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()
csv_writer.writerow(header)
count += 1
# Write data to CSV file
csv_writer.writerow(tmp.values())
# Close the CSV file
data_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.