How CSV quoting works under RFC 4180
CSV has no single official standard, but RFC 4180 describes the format most spreadsheet programs expect. Each record is one line, fields are separated by commas, and any field containing a comma, a double quote or a line break must be wrapped in double quotes. A double quote inside a quoted field is written as two double quotes.
This converter quotes every field, whether it needs it or not. That is valid CSV and is the safest choice when values may contain commas, at the cost of a slightly larger file. Lines end with the carriage return plus line feed that RFC 4180 specifies. The header row is the union of keys across all objects, in the order they first appear, so a key that only exists in a later record still gets a column, and records without it get an empty cell.
CSV to JSON uses a full RFC 4180 parser: quoted fields may contain commas, line breaks and doubled quotes, and both CRLF and LF line endings are accepted.
Worked example: one record, four kinds of value
Convert the record { "name": "Ana \"AJ\" Lee", "city": "Pune, MH", "tags": ["a", "b"], "meta": { "x": 1 } } and the data row becomes: "Ana ""AJ"" Lee","Pune, MH","[""a"",""b""]","{""x"":1}".
The embedded quotes around AJ are doubled, so a spreadsheet shows Ana "AJ" Lee. The comma in Pune, MH is safe because the field is quoted. The tags array and the nested meta object are written into their cells as JSON text, ["a","b"] and {"x":1}, so no data is lost, but a spreadsheet treats them as plain text. Flattening nested data first, for example into meta_x, gives columns that are easier to sort and filter.
Opening the CSV in Excel without surprises
Most CSV complaints are really spreadsheet import problems. Knowing them in advance saves a round of cleanup:
- Accented characters can appear garbled, such as café instead of café, when Excel opens a UTF-8 file that has no byte order mark. The downloaded .csv file includes that mark, so Excel detects UTF-8 when you double-click it. If you copy the text instead and save it yourself, import through Data, From Text/CSV and choose UTF-8 as the file origin.
- Leading zeros disappear from postcodes, phone numbers and product codes, because Excel converts 00123 to the number 123. Import the column as Text to keep them.
- Numeric IDs longer than 15 digits lose their last digits in Excel, which stores numbers with 15 significant digits. Again, import those columns as Text.
- Values that look like dates, such as 3-4 or 1/2, may be converted to dates automatically.
Security and data-shape tips
If the JSON comes from users, beware of CSV formula injection. A cell beginning with =, +, - or @ can be executed as a formula when someone opens the file in a spreadsheet. When exporting user-supplied data for others to open, prefix such values with a single quote or strip the leading character on the server before export.
Going the other way, CSV carries no type information, so every value parsed back into JSON is a string. If a downstream system expects numbers or booleans, convert those fields after parsing, for example with Number(row.id) or row.active === "true". Files that use a semicolon or tab as the separator need converting to commas first.
JSON to CSV Converter: frequently asked questions
What is the difference between CSV and Excel files?
CSV is plain text containing only values, one record per line, with no formatting, formulas or multiple sheets. An .xlsx file is a zipped package that stores styles, formulas, types and multiple worksheets. CSV is the better interchange format between systems; xlsx is better for finished reports.
Why does my CSV open in a single column?
Some regional versions of Excel expect a semicolon as the separator, because the comma is used as the decimal mark. Use the import wizard and choose comma as the delimiter, or change the list separator in your system's regional settings.
Should all CSV values be quoted?
It is not required, but it is never wrong under RFC 4180. Quoting only fields that need it produces smaller files, while quoting every field protects against values with commas or quotes that were not anticipated.
How do I convert deeply nested JSON to CSV?
Flatten it first so each value has its own key, using a naming scheme like address.city or address_city. Arrays of child records usually need to become separate rows or a separate CSV file linked by an ID, because one cell cannot hold a table.
What is CSV injection?
It is an attack where a value starting with a formula character such as = is executed by a spreadsheet when the file is opened. It can expose data or run commands on vulnerable setups. Sanitise user-supplied values that start with =, +, - or @ before exporting.