CSV ⇄ JSON converter
Convert CSV to a JSON array of objects, or JSON back to CSV. Handles quoted fields and custom delimiters.
[
{
"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
- Choose the direction with the CSV → JSON / JSON → CSV toggle.
- Pick the Delimiter — Comma (default), Semicolon (common in European Excel exports) or Tab (TSV). The same setting is used when writing CSV.
- Paste your data into the input box. The output updates as you type.
- 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
| Situation | Behavior |
|---|---|
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 field | Preserved inside the cell (JSON shows it as \n) |
| Windows line endings (CRLF) | Carriage returns are dropped; rows split correctly |
| Row shorter than the header | Missing cells become empty strings "" |
| Row longer than the header | Extra cells are ignored (no header to map them to) |
| Duplicate header names | The later column overwrites the earlier one in each object |
| Leading UTF-8 BOM | Not stripped — remove it or the first key will carry it |
| Blank lines in the middle | Become objects whose every value is "" |
| Wrong delimiter selected | Everything 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 headera,b. - Missing keys write an empty cell;
nullandundefinedalso 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 needuser.address.citycolumns. - The output uses
\nline 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.
Related tools and snippets
- JSON formatter & validator — fix a JSON parse error before converting, or minify the output array.
- Text diff — compare two CSV exports to see which rows changed.
- Case converter — normalize header names to snake_case or camelCase before they become JSON keys.
- Text statistics — count lines to sanity-check the row count of a large file.
- Text and data tools overview — how the text utilities on WebTricks fit together.
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.