Code speaks JSON, spreadsheets speak CSV and Excel, and sooner or later you need to move data from one to the other. The three formats hold the same rows and columns — the trick is converting without mangling them. Here is how.
The quoting rule, shown rather than described. We put
[{"name":"Ada","dept":"R&D","hours":7.5},{"name":"Bo","dept":"Sales, EU","hours":8}]through our JSON to CSV converter and it returned:name,dept,hours Ada,R&D,7.5 Bo,"Sales, EU",8Look at the last line.
R&Dis left bare, butSales, EUgets double quotes — because it contains the delimiter itself. That single rule is what breaks most hand-written CSV exports: a comma inside a value silently turns one column into two. Copy the input and check it yourself.
What each format is for
- JSON — structured data for code and APIs. Tabular data is usually an array of objects:
[{"name":"Ann","age":30}, …], where each object is a row. - CSV — a plain-text table (comma-separated). Universal, tiny, and imported by almost everything.
- Excel (.xlsx) — a binary spreadsheet with formatting, multiple sheets and formulas. What most colleagues actually open.
JSON to CSV
The cleanest JSON to convert is an array of flat objects. Each object becomes a row; the keys become the header row. Nested objects don’t map neatly to a flat table, so flatten them first (or expect only the top level to convert).
Note also what the header row came from. Our converter emitted name,dept,hours by reading the keys of the first object — not by scanning every record. If your second record has an extra key, that key has nowhere to go, which is the practical reason to flatten and normalise before you export rather than after.
JSON to Excel
Same idea, but the output is an .xlsx file that opens directly in Excel, Numbers or Google Sheets — no import step. Ideal when you need to hand data to someone who lives in spreadsheets.
CSV or Excel back to JSON
Going the other way turns a spreadsheet into an array of objects your code can parse — great for seeding a database, feeding an API, or loading test data.
Flattening nested JSON
CSV and Excel are flat grids, so nesting has to be unrolled first. The usual convention is dot notation for the keys:
[{ "name": "Ann", "address": { "city": "Berlin", "zip": "10115" } }]
becomes a table with the columns name, address.city and address.zip. Arrays are trickier: a list of values is often joined into one cell ("red; green"), while a list of objects usually needs one row per item. Decide the shape before converting so the columns stay consistent.
Delimiters, quoting and encoding
Most CSV headaches come down to three details:
- Delimiters. “Comma-separated” isn’t universal. In many European locales the comma is the decimal mark, so Excel expects a semicolon instead. If the columns don’t split, switch the delimiter.
- Quoting. A value that contains the delimiter, a quote or a line break must be wrapped in double quotes, and inner quotes are doubled:
"She said ""hi""". - Encoding. Save as UTF-8. Excel often needs a byte-order mark (BOM) to show accented or CJK characters correctly; without it you get mojibake like
é.
Quoting is the part that decides whether a CSV survives the round trip, and one input settles it. We gave our own JSON ↔ CSV/Excel converter two records where one value contains a comma and another contains an ampersand:
[{"name":"Ada","dept":"R&D","hours":7.5},{"name":"Bo","dept":"Sales, EU","hours":8}]
and it returned
name,dept,hours
Ada,R&D,7.5
Bo,"Sales, EU",8
Only Sales, EU got quotes; R&D did not. That is the whole rule — a field is quoted when it contains the delimiter, a quote character, or a newline, and left bare otherwise. A converter that quoted everything would still be valid CSV but would double the file and break naive parsers that compare raw strings; one that quoted nothing would silently turn two records into three columns.
Why Excel mangles my numbers
Open a CSV in Excel and IDs like 00123 lose their leading zeros, long digit strings such as order numbers flip to scientific notation (1.23E+11), and anything that looks like a date gets “helpfully” reformatted. These are Excel display conversions, not bugs in your data. To keep them intact, format the column as Text before pasting, or import via Data → From Text/CSV and mark the column as text. Validate the source first with the common JSON errors guide so a stray comma doesn’t derail the whole conversion.
Do it in your browser — nothing uploaded
Data files often contain sensitive information, so a tool that uploads them is a risk. These run entirely on your device:
- JSON ⇄ CSV ⇄ Excel converter — paste JSON or CSV, or upload an .xlsx, and convert between all three.
- JSON formatter — clean up and validate your JSON first so the conversion is predictable.
Tips for clean results
- Make your JSON an array of objects with consistent keys — that maps 1:1 to columns.
- Validate the JSON first (a stray comma breaks everything).
- For Excel, remember the output is a real
.xlsx— no need to rename a CSV.
Master the array-of-objects shape and moving between JSON, CSV and Excel becomes a two-click, no-upload task.