Skip to content
Technology·1 min read·

CSV to JSON

Turn CSV with a header row into a JSON array of objects, including quoted commas and quotes.

The answer

The first row is the header. Each later row becomes an object whose keys are those headers. Quoted cells may contain commas and doubled quotes.

Result

JSON

[
  {
    "name": "Ada",
    "note": "hello, world"
  }
]

Data rows

1

What do you want to do next?

How this works

Quotes wrap a cell. A quote inside a quoted cell is written as two quotes. Line breaks inside a quoted cell stay in that cell. A quote that starts in the middle of an unquoted cell is rejected.

Every header must be present and unique. A data row may be shorter than the header; the missing cells are empty strings. A row with more cells than the header is rejected.

Practical steps

  1. 1

    Paste CSV that includes the header row.

  2. 2

    Confirm the JSON keys match that header.

  3. 3

    If a row is rejected, look for a missing closing quote.

Examples

  • A quoted comma

    The cell "hello, world" stays one value in the JSON.

Common mistakes

  • ×

    Splitting on every comma yourself and then using this tool’s output to check a file that was already damaged.

Frequently asked questions

Are numbers left as numbers?

No. Every cell is a string, which is what the CSV file actually contains.

Do I need a data row?

Yes. A header alone is not enough.

Sources