Home › Guides › CSV and JSON

How to convert CSV to JSON and back

Two formats for the same tabular data. Converting is easy; the quoting rules are where it goes wrong.

CSV is rows and columns as text. JSON is nested and typed. Converting between them is routine, and doing it by splitting on commas is the classic mistake.

Step-by-step

  1. Paste your data, or load a file.
  2. Choose a direction.
  3. Copy or download the result.

Why splitting on commas fails

A CSV field may be quoted, and a quoted field may contain commas, newlines, and escaped quotes. This is a single valid row with two fields:

"Smith, John","He said ""hello"""

Splitting on commas produces four broken fields. A conforming parser is required, and that is what this uses — quoted fields with embedded commas and line breaks come through intact.

Types

CSV has no types; everything is text. Converting to JSON means deciding whether "42" becomes a number and "true" becomes a boolean. Helpful usually, occasionally wrong — a postcode or a phone number with leading zeros must stay a string, or the zeros vanish. Check any column of identifiers after conversion.

The header row

The first row is treated as field names, which is the usual convention. If your file has no header, the first row of data will be consumed as one — check the output rather than assuming.

Flat in, nested out

A CSV is a rectangle: every row has the same columns and no column contains structure. JSON is a tree. Converting the first into the second means deciding how much of the tree you want, and the honest default is none — one flat object per row, keys taken from the header.

Where nesting is wanted, the usual convention is a dotted header: address.city becoming an address object with a city inside it. It works, and it is ambiguous in exactly one place: a column genuinely named with a dot in it can no longer be told apart from a path. If your headers contain dots that are part of the name, either rename them or keep the output flat, because no convention resolves that automatically.

Empty, null and missing are three different things

A CSV has one way to say "nothing": an empty cell. JSON has three, and they do not mean the same thing. The key can be absent, which usually means unknown or not applicable. It can be present with a value of null, which asserts that there is deliberately no value. Or it can hold an empty string, which says the value is known and is the empty text.

Nothing in the CSV distinguishes these, so the conversion has to pick one and apply it everywhere, and the right choice depends on what consumes the output. Systems that treat a missing key as "leave the existing value alone" and a null as "clear it" will do materially different things to your data depending on which one you emitted — which is worth checking before a bulk import rather than after.

Frequently asked questions

Does it handle commas inside quoted fields?

Yes. A conforming parser is used, so quoted fields containing commas, newlines and escaped quotes are handled correctly.

Why did my leading zeros disappear?

The column was interpreted as numeric. Identifiers such as postcodes and phone numbers need to stay text — check any such column after converting.

Is there a size limit?

It is bounded by your device's memory rather than an imposed cap, since everything runs locally.

Open the developer tools →