CSV and JSON converter
Convert CSV to a JSON array of objects or arrays, or JSON back to CSV. Detects the delimiter and reads Dutch Excel files with semicolons and decimal commas.
Code examples
Copy and paste these into your own project. Each one uses only the language's standard library, so there is nothing to install.
const text = 'name,city\nAnn,Utrecht\nBob,"Den Haag, NL"\n'
const trimmed = text.trimEnd()
const records = [[]]
for (const match of trimmed.matchAll(/("(?:[^"]|"")*"|[^,\n]*)(,|\n|$)/gu)) {
if (match.index === trimmed.length) break
const [, field, end] = match
records.at(-1).push(field.startsWith('"') ? field.slice(1, -1).replaceAll('""', '"') : field)
if (end === '\n') records.push([])
}
const [header, ...rows] = records
const objects = rows.map((row) => Object.fromEntries(header.map((name, i) => [name, row[i]])))
console.log(JSON.stringify(objects))What it does
Converts CSV into a JSON array and JSON back into CSV. It reads RFC 4180 CSV: quoted fields, doubled quotes and line breaks inside a field.
How to use it
- Paste CSV or JSON, or drop a file.
- Choose CSV to JSON or JSON to CSV. Leave the delimiter and decimals on Detect, or set them yourself.
- Copy or download the result, or use Use output as input to turn it into the next input.
Examples
The CSV name;price / cheese;12,50 becomes [{"name": "cheese", "price": 12.5}], and with Header row off it becomes [["name", "price"], ["cheese", 12.5]].
Good to know
- With the header row on, every row becomes an object keyed by the column names; a row with a different number of fields is reported by row number.
- The delimiter is detected from the first rows: comma, semicolon, tab or pipe. Dutch Excel writes semicolons and decimal commas, which Detect reads as 12.5.
- A value becomes a number only when it reads back the same, so
007,1.50and very long numbers stay text. Turn off number reading to keep everything as text. - JSON to CSV needs an array of objects (columns are the union of the keys) or an array of arrays. Nested values are written as JSON text.
How does it read a CSV file?
It follows RFC 4180: fields are separated by a delimiter, a field in double quotes may hold the delimiter and line breaks, and a quote inside is written twice. The delimiter is detected from the first rows: comma, semicolon, tab or pipe.
Frequently asked questions
Why do my numbers become text, or the other way round?
A value only becomes a number when it reads back exactly the same, so 007, 1.50 and very long numbers stay text. Turn off “Read numbers and true/false” to keep everything as text.
What is the Dutch Excel format?
Excel in the Netherlands writes semicolons between fields and a comma as the decimal mark. With the delimiter or decimals on “Detect”, 12,50 is read as 12.5, and JSON to CSV writes a semicolon file when you pick a decimal comma.
Is my data sent anywhere?
No. The conversion happens in your browser. What you paste is never sent to our servers.