π Contents
Why JSON β CSV Isn't as Simple as It Looks
JSON and CSV are fundamentally different data models:
- JSON is hierarchical. Objects contain objects contain arrays contain objects. Arbitrary depth. Variable structure per record.
- CSV is flat. Rows and columns. Every row has the same columns in the same order. Two dimensions only.
Converting JSON to CSV means flattening a tree into a table. This is lossy β information gets discarded or restructured. The question isn't whether you can convert, it's what you lose in the process.
How Nested JSON Gets Flattened Into Columns
Consider this JSON:
{
"users": [
{
"id": 1,
"name": "Alice",
"address": {
"city": "New York",
"zip": "10001"
}
}
]
}
The converter must flatten address.city and address.zip into columns. It does this by concatenating the key path with a separator (usually dot or underscore):
| id | name | address.city | address.zip |
|---|---|---|---|
| 1 | Alice | New York | 10001 |
This works for one level of nesting. For deeper nesting (user.orders[0].items[2].sku), the column names become unwieldy. Most converters cap at 2-3 levels of depth and either ignore deeper fields or JSON-stringify them into a single cell.
Arrays in JSON: The Biggest Conversion Headache
Arrays are the hard part. What do you do with an array field like "tags": ["javascript", "react", "css"]?
Three approaches, each with tradeoffs:
- JSON-stringify the array β Cell contains
["javascript","react","css"]. Preserves all data but the CSV cell isn't spreadsheet-friendly (you can't filter by "javascript" easily). - Create separate columns β tags_0, tags_1, tags_2. Spreadsheet-friendly but breaks when arrays have different lengths (one record has 2 tags, another has 15).
- Comma-join into one cell β Cell contains
"javascript, react, css". Readable, filterable, but breaks if values contain commas (the CSV delimiter).
Our JSON to CSV converter defaults to JSON-stringify for arrays (preserves all data) with the option to comma-join or expand into columns.
Common Conversion Problems (And Fixes)
1. Inconsistent keys across records
Record 1 has {"name": "Alice", "email": "alice@..."}. Record 2 has {"name": "Bob", "phone": "555-..."}. The CSV needs columns for both email and phone. The converter must scan all records first to build the complete column list before writing any rows.
2. Top-level JSON that isn't an array
If the JSON is {"results": [{"id": 1}, {"id": 2}]}, the converter needs to find the array. Most tools let you specify the path (results) or auto-detect the first array.
3. CSV escaping
If a JSON string value contains a comma, double-quote, or newline, it must be escaped in CSV output. A value like He said, "Hello" becomes "He said, ""Hello""" in proper CSV. Missing escaping creates misaligned columns that silently corrupt data.
4. Unicode and encoding
JSON is always UTF-8. CSV has no inherent encoding β it's just bytes. If you open a UTF-8 CSV in Excel without the BOM, non-ASCII characters (Γ©, δΈζ, π) garble. Always add BOM for Excel compatibility, or open via Data β Import and specify UTF-8.
Free JSON to CSV Tools β Plus the Reverse
- JSON to CSV β Paste JSON, get CSV. Handles nested objects, arrays, and inconsistent records. Download as .csv file.
- CSV to JSON β The reverse. Paste CSV, get JSON array of objects. Useful when someone sends you a spreadsheet and you need JSON for an API or config.
- JSON Formatter β If the JSON is minified and you can't even see the structure, format it first, then convert.
- CSV Cleaner β After conversion, clean the CSV: trim whitespace, standardize nulls, strip BOM characters.