Who usually asks for the CSV
- A colleague in finance or operations wants to filter an API response in Excel, not read JSON
- An admin panel exports a JSON list and you want totals or a pivot table in Google Sheets
- A system only offers CSV import, while the data you have is a JSON dump
Two records, step by step
Take [{"id":1,"name":"Kim, Minji","memo":"says \"hi\"","vip":true},{"id":2,"name":"Lee","city":"Busan","vip":null,"tags":["a","b"],"addr":{"zip":"04524","gu":"중구"}}]. The header lists every key in the order it first appears: id, name, memo, vip, city, tags, addr.
- 1Row one is 1,"Kim, Minji","says ""hi""",true,,, — the name with a comma is quoted, the quotes inside memo are doubled, and city, tags and addr, which this record lacks, are empty.
- 2Row two is 2,Lee,,,Busan,… — the null in vip is also an empty cell, so once in CSV a null and a missing key look exactly the same.
- 3The tags array goes into one cell as JSON text, "[""a"",""b""]". With the a.b option, addr becomes two columns, addr.zip (04524) and addr.gu (중구); arrays stay as text either way.
- 4Every row ends in CRLF (\r\n), the line ending RFC 4180 describes and the one Excel on Windows and most CSV importers expect.
Two places where numbers change
This conversion reads the JSON into JavaScript values before writing the table, so unlike the JSON formatter it does not keep number tokens as written. {"order":12345678901234567890,"n":1.10} comes out as 12345678901234567000 and 1.1. If long identifiers such as order or account numbers matter, have the source send them as strings.
The second place is Excel itself. Its number precision is 15 digits, so a 16-digit number opened as a number gets its last digits replaced by zeros, and values with leading zeros such as "00123" or the postcode "04524" are intact in the CSV but lose their zeros when the file is opened by double-clicking. Open such files with Excel’s From Text/CSV import and set those columns to Text.
Choosing the separator
- Comma: the default, and what Google Sheets, English- and Korean-locale Excel and nearly every CSV library expect.
- Semicolon: in locales that write decimals with a comma, such as Germany or France, Excel’s list separator is a semicolon, and a comma file opens with everything in column A. With semicolons, "Kim, Minji" no longer needs quotes.
- Tab: handy when you copy the result and paste it straight into spreadsheet cells, and it cuts down on quoting when the data is full of commas.
The cost of the formula guard
OWASP warns that cells beginning with =, +, -, @, a tab or a carriage return can run as formulas when a spreadsheet opens the file, and suggests prefixing them with a single quote. The tool writes the text value "=1+2" as '=1+2. A JSON number such as -5 is left alone, because a number cannot be a formula and a prefix would stop Excel treating it as a number; the string "-5" does get the quote.
That apostrophe is a real character in the file. If the CSV is headed for a database import or another program rather than a spreadsheet, add a step that strips the leading quote from those columns, or the apostrophe is stored as part of the value.