Skip to content
WebTricks

CSV ⇄ JSON converter

Convert CSV to a JSON array of objects, or JSON back to CSV. Handles quoted fields and custom delimiters.

JSON
[
  {
    "name": "Ada",
    "role": "Engineer"
  },
  {
    "name": "Grace",
    "role": "Rear Admiral, US Navy"
  }
]

What this CSV / JSON converter does

The tool converts in both directions. CSV → JSON reads the first row as headers and emits a pretty-printed array of objects, one per data row. JSON → CSV takes an array of objects, collects every key it sees as the header row and writes one line per object, quoting cells only when they need it. The CSV parser is a small state machine that follows RFC 4180: quoted fields can hold the delimiter, newlines and escaped quotes. Conversion is live and happens in your browser.

How to use it

  1. Choose the direction with the CSV → JSON / JSON → CSV toggle.
  2. Pick the Delimiter — Comma (default), Semicolon (common in European Excel exports) or Tab (TSV). The same setting is used when writing CSV.
  3. Paste your data into the input box. The output updates as you type.
  4. Fix any red error (for JSON input: a parse error or the wrong top-level shape), then click Copy to take the result.

Worked example

Input CSV (note the quoted cell containing a comma):

name,role
Ada,Engineer
Grace,"Rear Admiral, US Navy"

Output JSON:

[
  { "name": "Ada", "role": "Engineer" },
  { "name": "Grace", "role": "Rear Admiral, US Navy" }
]

Run that JSON back through JSON → CSV and you get the original file: the second role is re-quoted because it contains the delimiter. A cell is quoted on output only when it contains the delimiter, a double quote or a newline; quotes inside a cell are doubled (""), which is the standard escape.

CSV edge cases and how the parser treats them

SituationBehavior
Quoted field with a comma, "Doe, Jane"Kept as one cell: Doe, Jane
Doubled quotes, "She said ""hi"""Decoded to She said "hi"
Line break inside a quoted fieldPreserved inside the cell (JSON shows it as \n)
Windows line endings (CRLF)Carriage returns are dropped; rows split correctly
Row shorter than the headerMissing cells become empty strings ""
Row longer than the headerExtra cells are ignored (no header to map them to)
Duplicate header namesThe later column overwrites the earlier one in each object
Leading UTF-8 BOMNot stripped — remove it or the first key will carry it
Blank lines in the middleBecome objects whose every value is ""
Wrong delimiter selectedEverything lands in a single column — change the dropdown

Numbers, booleans and dates all stay strings. Converting "true" to true or "2024-01-05" to a Date is a one-line map() in your code, and doing it there means you decide which columns are typed rather than a heuristic.

JSON → CSV details

  • Header order is the order in which keys are first encountered across the whole array, so [{"a":1},{"b":2,"a":3}] produces the header a,b.
  • Missing keys write an empty cell; null and undefined also become empty.
  • Numbers and booleans are written as their string form (42, true).
  • Nested objects and arrays are not flattened. An object becomes [object Object] and an array is joined with commas, which will then be quoted. Flatten first if you need user.address.city columns.
  • The output uses \n line endings and no BOM. If Excel shows accented characters wrong when you open the file, save it as UTF-8 with BOM or import via Data → From Text and choose UTF-8.

FAQ

Does it keep numbers as numbers?

No. CSV has no types, so every cell becomes a JSON string. That is deliberate — guessing would turn ZIP code 02134 into 2134 and version 1.10 into 1.1. Cast the fields you know are numeric in your own code.

Can it handle commas or line breaks inside a field?

Yes. A field wrapped in double quotes may contain the delimiter, line breaks and doubled quotes ("") exactly as RFC 4180 describes, and the converter preserves them.

My file uses semicolons — why is everything one column?

Excel in many European locales exports with semicolons. Switch the Delimiter dropdown to Semicolon (or Tab for TSV) and the columns split correctly.

What shape does the JSON input need for JSON → CSV?

A top-level array of flat objects, for example [{"name":"Ada","role":"Engineer"}]. A single object or an array of arrays is rejected with an "Expected a JSON array of objects" error.

What happens to nested objects when converting JSON to CSV?

They are stringified as [object Object], because CSV is flat. Flatten them first (for example address.city as a separate key) or stringify the nested value yourself before converting.

Why does my first column name start with a strange character?

Your file probably has a UTF-8 byte-order mark (BOM) that Excel adds. The parser does not strip it, so it becomes part of the first header. Delete the invisible first character and the key will be clean.