How to use the csv and json converter
- Choose CSV to JSON or JSON to CSV. A small sample is loaded for each direction.
- Paste your text, or open a file up to 3 MB. Choose the separator, such as comma, semicolon, tab or pipe.
- Set the options: whether the first row holds column names, whether to convert numbers and true or false, whether to indent the JSON and which line ending to use for CSV.
- Read the result and notes, then Copy result, Download result, or Use result as input to check a round trip.
How CSV is read
CSV is read with the quoting rules of RFC 4180. A field may be wrapped in double quotes. Inside quotes, the separator and line breaks are part of the value, and a double quote is written as two quotes in a row. So the field "Says ""hello""" is the text Says "hello". Records end at a line break, which can be CRLF, LF or CR. A final line break does not create an empty record. A byte order mark at the start of a file is ignored.
The reader reports problems it cannot guess around: a quoted field that never closes, or text between a closing quote and the next separator. A quote in the middle of an unquoted field is kept as a plain character. The page shows how many records and columns it found.
Types and column names
By default every value stays text, because a value like 007 or 1E5 may be an identifier and not a number. Turn on conversion to turn plain numbers into JSON numbers and the words true and false into booleans. Numbers with more than 15 digits stay as text, because JavaScript cannot hold them exactly. Empty fields stay as empty text.
With a header row, each record becomes an object with the column names as keys. Blank names become column_1, column_2 and so on, and a repeated name gets a number added so no value is lost. Rows with the wrong number of fields are noted, with missing values left empty. Without a header, every record is an array of values.
JSON to CSV
The JSON can be an array of objects, an array of arrays, an array of plain values or a single object. For objects, the columns are every key found, in the order they first appear, and a missing key gives an empty cell. Nested objects and arrays are written as JSON text inside one cell. A cell is put in quotes when it holds the separator, a quote, a line break or spaces at either end, and quotes inside are doubled. JSON is read with the browser's own parser, with no code evaluated.
Large integers in JSON lose precision when read by a browser, so a number over 15 digits may change. Put such values in quotes in the source. Spreadsheet programs may treat a cell that starts with =, +, - or @ as a formula, so check data from people you do not trust before you open it. To view a JSON file as a tree first, use the JSON viewer, and to make tables for a page see the Markdown table generator or the HTML table generator. To find the differences between two lists, try the compare two lists tool.
Assumptions and limits
- CSV follows RFC 4180 with a choice of separator. A quote opens a quoted field only at the start of a field.
- Values stay as text unless you turn on conversion, and numbers over 15 digits always stay as text.
- JSON to CSV writes nested values as JSON text in one cell. Deeper flattening into separate columns is not done.
- Input is limited to 3 MB, and everything runs in your browser.
Frequently asked questions
How do I convert CSV to JSON?
Paste the CSV, keep the first row as column names, and the tool returns a JSON array with one object per row. Turn on conversion if you want numbers and true or false as real JSON types.
How are commas and quotes inside a CSV field handled?
A field in double quotes can hold commas and line breaks, and a double quote inside it is written as two quotes. The reader follows RFC 4180, so "Portland, OR" is one value.
Why are my numbers shown as text in the JSON?
By default values stay as text so identifiers such as 007 are not changed. Tick the option to convert numbers and true or false.
Can I convert a nested JSON file to CSV?
Yes, but nested objects and arrays are written as JSON text inside a single cell. If you need each nested value in its own column, flatten the JSON first.