Skip to content
FindTool

    CSV to JSON

    Turn CSV or TSV into a JSON array, with header detection and automatic type inference.

    CSV to JSON tool

    What this tool does

    This converter reads CSV the way RFC 4180 defines it rather than by splitting on commas. A field wrapped in double quotes may contain the delimiter, a line break, or a doubled quote standing for a literal one, and all three survive the trip intact. The header row becomes the object keys; each following row becomes one object in the array.

    The delimiter is detected by test-parsing the start of the file with each candidate and keeping the one that produces a consistent column count — so a file full of commas inside quoted, semicolon-separated fields is read correctly. Ragged rows are padded with null and reported rather than silently dropped.

    Common uses

    • Turning a spreadsheet export into fixtures or seed data for tests.
    • Feeding a CSV report into a script, an API request body or a JSON-only import.
    • Inspecting a file whose delimiter or quoting you are not sure about, before automating it.
    • Converting a database dump into a shape you can filter with jq.
    • Rebuilding structure from flat exports, using the dotted-key option.

    A short example

    This CSV, with a comma and a doubled quote inside quoted fields:

    id,name,active
    1042,"Lovelace, Ada",true
    1043,"Katherine ""Kat"" Johnson",false

    becomes:

    [
      { "id": 1042, "name": "Lovelace, Ada", "active": true },
      { "id": 1043, "name": "Katherine \"Kat\" Johnson", "active": false }
    ]

    What type inference will and will not do

    CSV has no types — every cell is text — so converting 42 to a number is a guess. It is usually the right guess, and the rules here are deliberately conservative:

    • Leading zeros stay text. 01234 is a postcode, an account number or a product code far more often than it is the number 1,234.
    • Long integers stay text. Anything over 15 digits cannot round-trip through an IEEE-754 double, so a 19-digit snowflake ID is left exactly as written.
    • Only true, false and null convert, case-insensitively. yes, Y, NA and - are conventions, not values, so they stay strings.
    • Empty cells become null, not empty strings.

    Turn inference off when you need every value to stay exactly as it appeared in the file.

    Worth knowing

    A leading byte order mark is stripped automatically, because otherwise the first column would be named id and every lookup against id would fail — a bug that costs people a surprising amount of time with Excel exports. Two more things worth remembering: quoted fields containing newlines mean you cannot count records by counting lines, and if your data arrives one record per line already, you may want JSON Lines instead of one big array — it streams, where a single top-level array has to be read whole before anything inside it is valid.

    Frequently asked questions

    Why do accented characters arrive broken when the file came from Excel?

    Excel’s plain Save as CSV on Windows writes the machine’s legacy ANSI code page rather than UTF-8, so José leaves the spreadsheet as bytes that no UTF-8 reader can interpret. Pick CSV UTF-8 (Comma delimited) in the save dialog, offered since Excel 2016, and the text survives. Re-exporting is the only reliable repair — the damaged characters cannot be guessed back afterwards.

    What happens when two columns share the same header?

    An object cannot hold the same key twice, so the second one is renamed with a numeric suffix: two id columns become id and id_2, and the rename appears in the warnings rather than happening silently. A blank header cell becomes column_4, numbered by position. Fix the names in the source if you need stable keys, since the suffix follows column order.

    Can I paste a TSV or cells copied straight out of a spreadsheet?

    Yes. Copying a selection from Excel or Sheets puts tab-separated text on the clipboard, and tab is one of the delimiters probed during detection. Worth knowing: the IANA text/tab-separated-values format has no quoting rules whatsoever, so a genuine TSV cannot represent a cell containing a tab — what a spreadsheet copies is really CSV with tabs, which quotes those cells properly.