Batch Convert JSON to CSV
Convert paginated API responses, webhook payloads, and JSON exports to CSV format. Merge multiple JSON files into a single spreadsheet.
The Problem
You have 50 paginated API responses as JSON files and need them in a single CSV for analysis in Excel or Google Sheets. Manually copy-pasting each response into a converter is too slow.
Why Batch Processing Matters
JSON-to-CSV conversion at scale is needed for API data exports (paginated responses, webhook histories), data warehousing ETL pipelines, reporting dashboards that consume CSV, and migration between systems that speak different formats.
Common Use Cases
- Merge paginated API responses into one CSV for analysis
- Convert webhook payload logs to spreadsheet format
- Export Elasticsearch or MongoDB query results to CSV
- Prepare JSON API data for import into Google Sheets or Excel
Step-by-Step Instructions
Inspect JSON structure
Check if your JSON files contain arrays of objects ([{...}, {...}]) or nested structures. Flat arrays convert directly; nested data needs flattening first.
Flatten nested fields
For nested JSON like {"user": {"name": "Alice"}}, flatten to {"user.name": "Alice"} so each value maps to a CSV column.
Merge multiple files
Concatenate arrays from all files into a single list. Handle inconsistent schemas by collecting all possible column names.
Export to CSV
Write the merged data to CSV with proper escaping for commas, quotes, and newlines in values.
Code Examples
# Convert a single JSON array to CSV
jq -r '(.[0] | keys_unsorted) as $keys |
($keys | @csv),
(.[] | [.[$keys[]]] | @csv)' data.json > output.csv
# Merge multiple JSON files (each containing an array) into one CSV
jq -s '[.[][]]' page_*.json | \
jq -r '(.[0] | keys_unsorted) as $keys |
($keys | @csv),
(.[] | [.[$keys[]]] | @csv)' > merged.csv
# Convert NDJSON (newline-delimited JSON) to CSV
cat events.ndjson | \
jq -rs '(.[0] | keys_unsorted) as $keys |
($keys | @csv),
(.[] | [.[$keys[]]] | @csv)' > events.csv
Single vs Batch Comparison
Paste JSON array → get CSV table with headers
$ ls api_responses/ page_001.json page_002.json page_003.json ... page_050.json $ python merge_json_to_csv.py Merged 2,450 records from 50 files $ head -3 merged_output.csv id,name,email,created_at,plan.name,plan.price 1,"Alice Smith","[email protected]","2026-01-15","Pro",29.99 2,"Bob Jones","[email protected]","2026-01-16","Free",0
Frequently Asked Questions
How do I handle nested JSON when converting to CSV?
Flatten nested objects using dot notation: {"user": {"name": "Alice"}} becomes a column user.name with value Alice. Arrays can be stringified as JSON or split into multiple rows depending on your needs.
What about inconsistent JSON schemas across files?
Collect all unique keys across all records to build the complete header row. Records missing a field get an empty value for that column. The Python and Node.js scripts above handle this automatically.
Can I convert CSV back to JSON?
Yes. Use csvkit's csvjson command, Python's csv.DictReader, or our JSON Formatter to structure the output.
Related Batch Guides
Try these tools interactively
Each tool runs in your browser with no signup required. Process single items instantly.