Convert CSV to JSON
The first CSV row becomes the keys and every later row becomes one JSON object. A field in double quotes may contain commas, so "Austin, TX" stays one value.
Last reviewed 2026-11-04.
Worked example
This CSV has 2 data rows and 3 columns:
$ name,age,city
Ada,36,London
Lin,29,"Austin, TX"
becomes
[
{
"name": "Ada",
"age": "36",
"city": "London"
},
{
"name": "Lin",
"age": "29",
"city": "Austin, TX"
}
]Everything is a string by default
CSV has no types, so 36 arrives as the string "36". Turn on "Numbers, true, false and empty as null" to get real types. The same data then converts to:
$ [{"name":"Ada","age":36,"active":true},{"name":"Lin","age":29,"active":null}]Common mistakes
- Splitting on commas with
line.split(","). It breaks on quoted fields; use a real parser. - A semicolon-delimited export (common in European Excel) read as comma-delimited gives one column. Set the delimiter or use detect.
- Leading zeros such as
00123become123when numbers are converted. Keep them as strings if they are IDs. - To go the other way, see JSON to CSV.
Running this on a server
The conversion runs in your browser, so the data never leaves your machine. To run the same conversion on a server in a pipeline, the hosting guide compares small hosts.
Frequently asked questions
How do I convert CSV to JSON in JavaScript?
Use a parser that handles quotes, such as the csv-parse or papaparse packages, then JSON.stringify the rows. Do not split on commas.
Does it need a header row?
No. Without one, the output is an array of arrays.
Is my file uploaded?
No. The conversion runs locally in the page.
Sources
- RFC 4180: Common Format and MIME Type for CSV Files checked 2026-11-04
- RFC 8259: The JSON Data Interchange Format checked 2026-11-04