Converting CSV to JSON turns the world's oldest tabular format into the modern web's favorite data format. Whether you're importing a spreadsheet export into a Node.js script, feeding a contact list to an HTTP API, or migrating off Excel into a JSON-based config system, this tool gives you clean, predictable JSON from any well-formed CSV. The parser auto-detects headers from the first row and respects RFC 4180 quoted fields, so commas-inside-strings and embedded newlines parse correctly.
How CSV to JSON Conversion Works
The parser splits the input on newlines (handling \n, \r\n, and quoted multi-line fields), takes the first row as headers, then maps each subsequent row to an object where keys come from the headers and values come from the row. Quoted fields are unescaped (doubled quotes become a single quote). Empty cells become empty strings; type inference is intentionally NOT done — everything stays a string so you don't get surprised by phone numbers being converted to scientific notation or leading zeros being stripped from IDs.
When to Convert CSV to JSON
- API ingestion — most REST and GraphQL APIs accept JSON; convert your spreadsheet first.
- Data seeding — bootstrap a database from a CSV by converting to JSON, then bulk-inserting.
- Frontend consumption — React, Vue, Svelte apps work better with JSON than parsing CSV in the browser.
- Config migration — moving from Excel-based configs to a JSON-driven app? Start here.
- NoSQL imports — MongoDB
mongoimport --jsonArray, DynamoDB batch writes, Firebase — all want JSON.
CSV to JSON in Code
function csvToJSON(csv) {
const [headerLine, ...lines] = csv.trim().split('\n');
const headers = headerLine.split(',');
return lines.map(line => {
const values = line.split(',');
return Object.fromEntries(
headers.map((h, i) => [h, values[i] ?? ''])
);
});
}
// For RFC 4180 quoted fields, use a proper parser like 'papaparse' or 'csv-parse'.
To go back the other way, use our JSON to CSV converter.
CSV Dialect & Encoding Gotchas
CSV is not a single standard — it's a family of similar formats. Delimiters can be commas, semicolons (common in European locales), tabs (TSV), or pipes. Encoding is usually UTF-8 but Excel exports sometimes default to Windows-1252 or UTF-16 with a BOM. This tool assumes comma delimiter and UTF-8 encoding. If your file uses a different delimiter, find-and-replace it to comma first. If you see ¿¿¿ or garbled characters, re-save the source file as UTF-8.