Someone from sales sends you customers_final_v3.csv, and the app you're building wants JSON. You could write a parser, or you could paste the file into a converter and get on with your day. This guide covers what's going on under the hood, so the output doesn't surprise you.
What is the CSV format?
CSV stands for comma-separated values. It's a table saved as plain text: each line is a record, and the fields in a line are separated by a delimiter, usually a comma. Because it's just text, almost every spreadsheet, database and programming language can read and write it.
It's less simple than it looks. A field that contains the delimiter, a line break or a double quote has to be wrapped in double quotes. Many European versions of Excel use semicolons instead of commas. And tab-separated files (TSV) are the same idea with tabs.
Why convert CSV to JSON?
JSON is what web APIs, config files and JavaScript apps expect. CSV is great for flat tables, but JSON gives every value a named key and can nest data. So when a spreadsheet needs to feed a web app, an API or a document database such as MongoDB, converting it to JSON is usually step one.
You'll run into this when you migrate an export from an older system, turn a dataset into mock data for a React or Vue front end, or keep test fixtures in a spreadsheet where each row is one test case.
Common delimiters
Despite the name, a “comma-separated” file isn't always separated by commas:
- Comma (
,): the standard and most common. - Semicolon (
;): the default in many European Excel locales. - Tab: used by TSV files.
- Pipe (
|): found in some legacy exports.
Picking the right one matters. Split a semicolon-separated file on commas and each line comes out as one giant field. If your output looks like that, the delimiter is the first thing to check.
How the header row shapes the output
Most CSV files start with a header row of column names. The converter always treats the first line as the header. Every line after it becomes a JSON object, with the header names as keys:
name,city,plan
Priya Patel,Bengaluru,pro
Marco Rossi,Milan,free[
{ "name": "Priya Patel", "city": "Bengaluru", "plan": "pro" },
{ "name": "Marco Rossi", "city": "Milan", "plan": "free" }
]If your file has no header row, add one before converting. Otherwise your first customer quietly becomes the column names and disappears from the output.
How to use the CSV to JSON converter
- Open the CSV to JSON converter and paste your CSV, header row first. You need at least a header and one data row.
- Choose the Delimiter: comma, tab, semicolon or pipe.
- Select Convert. The JSON array appears below, and Copy puts it on your clipboard.
The conversion runs in your browser, so your customer list isn't uploaded anywhere.
What the converter does and doesn't handle
The tool reads CSV the way RFC 4180 describes it, so the awkward rows that break a quick split(",") come through intact. Here are the rules it follows:
- Every value is a string.
30becomes"30"andtruebecomes"true". Convert types afterwards if you need numbers or booleans. - Quoted fields are kept whole. A delimiter or line break inside double quotes stays part of the value, so
"Rossi, Marco"is one name, not two. A doubled quote ("") inside a quoted field becomes a single". - Whitespace around unquoted values is trimmed. Inside quotes it’s kept exactly as typed.
- Missing fields become empty strings. Extra fields beyond the header are dropped.
- Blank lines are skipped, and both Windows (CRLF) and Unix (LF) line endings work.
- A quote that’s never closed stops the conversion with an error, rather than quietly swallowing the rest of the file into one cell.
Converting CSV to JSON in JavaScript
If your data is clean (no quotes, no commas inside values), a few lines of JavaScript will do:
function csvToJson(csv, delimiter = ",") {
const lines = csv.trim().split(/\r?\n/);
const headers = lines[0].split(delimiter).map((h) => h.trim());
return lines.slice(1).map((line) => {
const values = line.split(delimiter);
return Object.fromEntries(
headers.map((header, i) => [header, values[i]?.trim() ?? ""]),
);
});
}
const csv = "name,city\nPriya,Bengaluru\nMarco,Milan";
console.log(JSON.stringify(csvToJson(csv), null, 2));Unlike the online tool, this shortcut doesn’t handle quoted fields or multiline values, and real-world CSV has a habit of containing both. For production data, use a library such as PapaParse, which also has a dynamicTyping option to turn numbers and booleans into real types.
