Data · 2 min read ·

JSON to CSV without losing a single field

Nested keys, optional fields and commas inside strings — how 4Dev flattens messy JSON into a spreadsheet-ready CSV.

Spreadsheets are flat; JSON isn't. Every JSON-to-CSV conversion has to decide what to do with nested objects, arrays and keys that only some records have. Here is exactly what the 4Dev converter does.

Every key gets a column

The header row is built from the keys of every object, in the order they first appear — not just from the first record. A record that is missing a key gets an empty cell, so columns never shift and optional fields never disappear.

[{"id":1,"name":"Ada"},
 {"id":2,"name":"Alan","note":"optional"}]

id,name,note
1,Ada,
2,Alan,optional

Nested objects become underscore columns

Objects are flattened by joining their keys with an underscore, so {"address":{"city":"Lisbon"}} becomes a column named address_city. An array of plain values goes into one cell ("admin, dev"), and an array of objects is kept as JSON text in its cell, so nothing is thrown away.

Commas and quotes are escaped for you

Any value that contains a comma, a double quote or a line break is wrapped in double quotes, and inner quotes are doubled — the standard CSV rule that Excel and Google Sheets expect.

2,"Alan, T.","says ""hi"""

Open the JSON to CSV converter