Tutorial · CSV → JSON · 3 min read

How to Convert CSV to JSON

Convert a CSV export into a JSON array of objects using the header row as keys, with quoted fields, embedded commas and newlines handled correctly.

Going from a spreadsheet to code usually means CSV to JSON. The header row becomes the keys, every following row becomes an object. The details that trip people up are quoting rules and values that are numbers in the sheet but strings in the JSON.

What you'll learn

  • Parse RFC 4180 style CSV including quoted commas and newlines
  • Map the header row to object keys
  • Decide how to treat numbers, empty cells and duplicate headers

Step by step

  1. Paste the CSV with its header row

    Open CSV to JSON and paste the text. The first row must be the header; everything after it is data.

  2. Click Convert

    Each row becomes an object keyed by the header. Values are strings; convert types in your code if you need numbers.

    id,name
    1,Ada
    2,"Grace, Hopper"
    
    →
    
    [
      { "id": "1", "name": "Ada" },
      { "id": "2", "name": "Grace, Hopper" }
    ]
  3. Check for a header-only file

    If only a header was found you get an empty array and a note saying so. Add data rows and convert again.

  4. Copy the JSON

    Copy Output and drop it into your code or a fixture file.

Open the tool with this example Runs in your browser. Nothing you paste is uploaded.

Common problems

Values are strings, not numbers

CSV has no types, so everything is text. Convert in your code, or post-process with a small script if you need numbers and booleans.

Rows have too few values

Missing trailing cells become empty strings. Check the source export for rows that were truncated.

FAQ

What about semicolon-separated files?

Replace the semicolons with commas first, taking care with quoted fields, or export the sheet again as comma-separated.