How to Convert JSON to CSV

Converting JSON to CSV works best when your JSON is an array of flat objects — `[{a:1,b:2},{a:3,b:4}]` maps cleanly to a 2-column CSV. Nested JSON needs flattening first. Below are the fastest methods in pandas, jq, and Node.js.

Generate matching mock data right now

No sign-up, runs 100% in your browser, exports straight to CSV.

pandas (Python)

import pandas as pd, json
with open('data.json') as f:
    data = json.load(f)
pd.json_normalize(data).to_csv('data.csv', index=False)

json_normalize flattens nested objects into dotted column names (address.city).

jq (command line)

jq -r '(.[0] | keys_unsorted), (.[] | [.[]]) | @csv' data.json > data.csv

Works for any flat array of objects, no install beyond jq.

Node.js

const fs = require('fs');
const data = JSON.parse(fs.readFileSync('data.json'));
const headers = Object.keys(data[0]);
const rows = data.map(o => headers.map(h => JSON.stringify(o[h] ?? '')).join(','));
fs.writeFileSync('data.csv', [headers.join(','), ...rows].join('\n'));

Frequently asked questions

What about nested arrays?

Either expand them into multiple rows (one row per child), or join them into a single string column. pandas `json_normalize` has a `record_path` parameter for the row-explosion approach.

How do I handle missing keys?

pandas and jq both fill missing keys with empty strings. In Node, use `?? ''`.

Related guides

Start generating free mock CSVs

High-fidelity mock tables for tests, demos, or models. No sign-ups, completely local.