How to convert JSON to CSV
The conversion itself takes a second. Getting a file that opens correctly and still means what the JSON meant takes four decisions.
Last reviewed
1 — Get the document into the right shape
CSV needs a list of rows, so the JSON needs to be an array of objects. If yours is an object wrapping the array — {"data": [...]}, which most APIs return — point the converter at the array, or extract it first.
If it is an object keyed by id, each value being an object, that also tabulates: the key becomes a column and each value becomes a row.
[
{ "id": 1, "name": "Ada", "team": { "name": "core" } },
{ "id": 2, "name": "Alan", "team": { "name": "infra" } }
]2 — Decide how nesting flattens
Dotted column names (team.name) are the standard answer and are reversible. Check the depth first: a deeply nested document flattens into hundreds of sparse columns, and at that point CSV is the wrong destination — the data wants a database table per level.
For arrays, choose between joining into one cell, one column per index, or one row per element. Joining is right for tags; one row per element is right when the array is really a child table.
3 — Choose the delimiter and quoting
- Comma is the default and needs quoting whenever a value contains a comma, a quote or a newline.
- Semicolon is what Excel expects in several European locales.
- Tab avoids quoting almost entirely and pastes cleanly into a spreadsheet, which is often the real goal.
- Inside a quoted field, a literal double quote is written twice ("").
4 — Decide what null becomes
An empty cell, the text "null", or the string "NA" — all three are used, and the receiving system cares. An empty cell is the least surprising default; the text "null" is the only one that survives a round trip back to JSON unambiguously.
Making it open properly in Excel
Add a UTF-8 BOM if any value is non-ASCII, otherwise Excel will mangle accented characters and anything non-Latin. Use the semicolon delimiter if your Excel is in a locale that expects one.
Be aware that Excel will still convert values that resemble dates, and will still lose precision on digit strings longer than 15 characters. If the file contains identifiers rather than measurements, TSV pasted into a pre-formatted text column is safer than a .csv double-click.
Check before you ship it
- Row count matches the array length, unless you chose to expand arrays into rows.
- The header contains every key, including ones that only some objects have.
- A value containing a comma is quoted, and one containing a quote has it doubled.
- Long numeric ids are unchanged, digit for digit.
Keep reading
- JSON vs CSV — CSV holds rows of text. JSON holds a typed tree. Every conversion between them either flattens something or invents something.
- How to open a JSON file — A .json file is plain text. Anything that opens a text file will open it — the question is what makes it readable.