Skip to the content

JSON to CSV Converter

Convert JSON to CSV and CSV back to JSON, with nested fields flattened.

CSV

Share this tool:TwitterFacebookLinkedInWhatsAppEmail

How nested JSON becomes a flat table

A CSV file is a grid, and JSON can be any shape, so the converter has to decide where everything goes. Take one order:

{"id": 7, "customer": {"name": "Mila", "address": {"city": "Utrecht"}},
 "tags": ["tea", "books"],
 "lines": [{"sku": "TP-200", "qty": 1}, {"sku": "GT-015", "qty": 3}]}

It becomes one row with these columns:

ColumnValueRule
id7A plain value keeps its key
customer.nameMilaA nested object adds its keys after a dot
customer.address.cityUtrecht
tagstea, booksA list of plain values is joined in one cell
lines.0.skuTP-200A list of objects is numbered from 0
lines.0.qty1
lines.1.skuGT-015
lines.1.qty3

The header is every key that occurs anywhere, in the order it first shows up. A row without that key gets an empty cell, and so does null.

An array gives one row per item. A single object gives one row. Many APIs wrap their rows, as in {"total": 2, "data": [...]}; when an object holds exactly one list of objects, that list is used as the rows and you can switch that off under the result.

Comma or semicolon?

RFC 4180, the closest thing CSV has to a standard, says comma. Excel follows the list separator of the computer's regional settings, and wherever decimals are written with a comma (Dutch, German, French and many more) that separator is a semicolon. A file with commas then opens in such an Excel with every row crammed into column A. If your file is meant for a colleague's Excel in one of those countries, choose the semicolon.

Going the other way, the delimiter is detected: comma, semicolon, tab and pipe are tried on the first twenty rows, and the one that gives every row the same number of fields wins. Fields in double quotes may contain the delimiter, line breaks and doubled quotes (""), as the RFC describes.

Accents in Excel

Excel reads a CSV file as UTF-8 only when the file starts with a byte order mark, three invisible bytes. Without it é shows up as é. Tick the byte order mark option before you download if the file goes to Excel. Leave it off for other programs: some of them treat those bytes as part of the first column name.

Cells that start with = + - or @

Spreadsheet programs treat such a cell as a formula, also when it comes from a CSV file. If your data holds text that other people typed, a "name" like =HYPERLINK(...) ends up as a live formula on the screen of whoever opens the export. The option to put a single quote in front makes those cells plain text. Numbers are left alone, so -5 stays a number. The quote is then part of the data, which is why the option is off by default: only use it for files that people will open in a spreadsheet.

From CSV to JSON

CSV has no types; everything is text. With the conversion option on, a field becomes a number when it is written exactly like a JSON number, so 42 and -1.5 do and 007, +31612345678 and 1,5 stay text. Numbers that JavaScript cannot hold exactly, such as 19-digit IDs, also stay text, so no digits get lost. true and false are recognised in any capitalisation and null only in lowercase.

Nesting dotted names is the reverse of the table above: address.city becomes an object and lines.0.sku a list. A round trip is not perfect, though. A list that was joined into one cell comes back as one string, and an empty string and null look the same in a CSV file.

Your data stays here

Both conversions run in your browser. Nothing you paste or open is uploaded, and only the options are remembered.

See all 12