Guides
How to convert JSON to CSV (and when you shouldn’t)
A practical guide to turning a JSON array of objects into CSV, how nested data is handled, and the edge cases that trip people up.
CSV is the lingua franca of spreadsheets and data imports, but most APIs speak JSON. Converting between them is easy when your JSON is a flat array of objects — and surprisingly subtle when it isn’t.
The ideal shape
CSV is a table: rows and columns. It maps cleanly onto a JSON array where every element is an object with the same keys:
[
{ "name": "Ada", "age": 36 },
{ "name": "Alan", "age": 41 }
]Each object becomes a row; each key becomes a column. Our converter reads the union of all keys so rows with missing fields still line up.
Nested objects and arrays
CSV has no concept of nesting. When a value is itself an object or array, you have two sensible options:
- Flatten it first — turn { "a": { "b": 1 } } into an a.b column.
- Serialize the value as a JSON string inside the cell.
If your data is deeply nested, flatten it before converting so each leaf becomes its own column.
Everything here runs in your browser — your data is never uploaded.
When not to use CSV
If your data is hierarchical, has repeated groups, or mixes types per field, CSV will lose information. Prefer keeping it as JSON, or convert to a format that preserves structure.