Format Bench › CSV to JSON

CSV to JSON Converter

Paste CSV and press To JSON. Quoted fields containing commas, quotes and newlines are parsed correctly, which is where naive split-on-comma converters fail.

Runs locally. What you paste never leaves this page.

Why splitting on commas is not enough

CSV looks trivial and is not. The format, described by RFC 4180, allows a field to be wrapped in double quotes, and a quoted field may contain the delimiter, literal newlines, and quote characters escaped by doubling them. A converter that splits each line on commas will mangle any file containing an address, a description, or any prose at all.

This parser is a proper character-by-character state machine. A field like "likes commas, and ""quotes""" is read as the single value likes commas, and "quotes", and a quoted field spanning several lines is kept as one value rather than being split into bogus rows.

Type inference, and when to turn it off

With inference enabled, values that look like numbers become numbers, true and false become booleans, and empty fields become null. That is usually what you want, and occasionally disastrous. Turn it off when the file contains:

  • Identifiers with leading zeros. A zip code of 02134 or a product code of 00891 becomes 2134 and 891, which is silent data corruption.
  • Long numeric identifiers. Anything beyond about sixteen digits exceeds the precision of a JavaScript number and will be altered. Credit card numbers, some order IDs and large database keys all fall in this range. This converter leaves a numeric string alone when converting it would change its text, which catches most of these, but the safe move is to disable inference.
  • Phone numbers and anything else where the leading characters matter.

Delimiters that are not commas

Tab-separated files are common in exports from spreadsheets and databases, and semicolons are the default in locales that use a comma as the decimal separator, which covers much of Europe. Pipe-delimited files show up in older data feeds. All four are selectable, and the same quoting rules apply regardless of which delimiter is in use.

Going the other way

Converting JSON to CSV takes an array of objects and produces a header row from the union of all keys across every object, not just the keys of the first one. This matters because JSON records are frequently ragged: an optional field present on only some records would be dropped entirely by a converter that samples only the first row. Missing values become empty cells.

Nested objects and arrays cannot be represented in a flat CSV cell, so they are serialised back to JSON text within the cell. That keeps the information rather than discarding it, though a genuinely nested dataset is usually better flattened deliberately before export.

Ragged rows

If rows have differing column counts, the conversion still completes and a warning is shown. Ragged rows almost always indicate an unescaped quote earlier in the file, which causes the parser to treat a delimiter as literal text. The warning is worth heeding rather than ignoring.

Questions

Does it handle commas inside quoted fields?

Yes. The parser is a proper state machine following RFC 4180, so quoted fields may contain the delimiter, doubled quotes and literal newlines, and are read as a single value.

Why did my zip code lose its leading zero?

Type inference read it as a number, and leading zeros are not significant in numbers. Untick Infer types to keep every field as a string. This matters for zip codes, product codes and phone numbers.

What happens to very long numeric IDs?

Numbers beyond roughly sixteen digits exceed JavaScript's precision. The converter leaves a numeric string unchanged when converting it would alter the text, but for files full of long identifiers it is safer to disable type inference entirely.

How are columns chosen when converting JSON to CSV?

From the union of keys across every object in the array, so optional fields that appear on only some records still get a column. Records missing that field get an empty cell.

Can it convert nested JSON?

Nested objects and arrays are serialised as JSON text inside the cell, because CSV has no nesting. For a genuinely nested dataset, flatten it deliberately first so the column names mean what you want.

Other tools