Convert JSON to CSV: 5 Methods Compared
JSON-to-CSV conversion sounds trivial until you encounter your first nested object, array of objects, or sparse JSON where keys differ between rows. Here are five battle-tested methods, ranked by use case.
The challenges
- Nested objects —
{ user: { name: "..." } }— flatten or preserve? - Nested arrays —
{ tags: ["a", "b"] }— join, JSON-stringify, or explode? - Inconsistent keys — different rows have different fields
- CSV escaping — commas in values, quotes in values, newlines in values
- Encoding — Excel doesn't open UTF-8 CSV correctly without BOM
Method 1: Browser-based tool (fastest for one-offs)
Paste JSON, get CSV. fmt.hjlabs.in/json-to-csv handles nested objects (auto-flattens with dot notation), preserves array order, and exports as Excel-compatible CSV.
Best for: data exports, ad-hoc conversions, sharing data with non-technical colleagues.
Method 2: jq (command line, scriptable)
# Simple flat JSON arraycat data.json | jq-r '(.[0] | keys_unsorted) as $keys | $keys, map([.[$keys[]]])[] | @csv'> data.csv# With headercat data.json | jq-r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv'> data.csv
Pros: no dependencies, scriptable in CI/CD, handles streams. Cons: incantation-heavy syntax, painful for nested data.
Method 3: Python (for serious data work)
importjson, csvwithopen('data.json')asf: data = json.load(f)# Flat JSON array of objectswithopen('out.csv','w')asf: writer = csv.DictWriter(f, fieldnames=data[0].keys()) writer.writeheader() writer.writerows(data)
For nested JSON, use pandas.json_normalize():
importpandasaspd df = pd.json_normalize(data) df.to_csv('out.csv', index=False)
Method 4: Node.js (for backend pipelines)
const{ Parser } =require('json2csv');constdata =require('./data.json');constparser =newParser();constcsv = parser.parse(data); fs.writeFileSync('out.csv', csv);
The json2csv library handles nested fields, custom delimiters, BOM for Excel, and streaming for large files.
Method 5: Excel / Google Sheets (for non-coders)
Google Sheets has built-in JSON import via the IMPORTDATA function, or paste JSON into a cell and use Apps Script.
Excel: Power Query → Get Data → From JSON. Handles nested data with a UI.
Edge cases and how each handles them
Commas/quotes/newlines in values
All five methods handle this correctly when the value is properly quoted. RFC 4180 says: wrap in ", escape internal " as "".
name,description "Smith, John","He said ""hello"""
Inconsistent keys (sparse JSON)
Best handled by Python pandas (auto-fills NaN) and our browser tool (auto-fills empty). jq and json2csv require explicit field list.
Nested objects
Standard flattening: { user: { name: "X" } } → column user.name. Most tools do this; jq doesn't natively (you write the path).
Arrays of values
Three options:
- Pipe-join:
"tag1|tag2|tag3" - JSON-stringify:
"[\"tag1\",\"tag2\"]" - Explode (one row per array element)
Pick based on what the consumer expects. Excel users prefer pipe-join.
Excel UTF-8 issue
Excel on Windows doesn't auto-detect UTF-8. Workaround: prepend a BOM (\xEF\xBB\xBF) to the file. Most modern tools do this when you set encoding: 'utf-8-sig'.
When to skip CSV
For data with deep nesting or arrays-of-objects, CSV is the wrong format. Consider:
- Parquet — columnar, preserves types, ideal for analytics
- JSONL — one JSON object per line, streamable
- SQLite database — proper relational model
Decision matrix
| Need | Best tool |
|---|---|
| One-off, share with colleague | fmt.hjlabs.in/json-to-csv |
| Bash pipeline / CI/CD | jq |
| Data science, big files | pandas |
| Backend service | json2csv (Node) |
| Non-coder workflow | Excel Power Query |
Bottom line
For 80% of conversions, a browser tool is fastest. For automation, learn jq. For complex nested data, use pandas. Don't try to roll your own CSV escaping — RFC 4180 has more edge cases than you'd expect.
Try the free dev tools suite
15+ tools. 100% client-side. No signup. No tracking.
Browse all tools →