CSV to JSON
Convert CSV data to a JSON array of objects. First row is treated as the header.
Converting spreadsheet data to JSON
CSV is the universal export format of spreadsheets and databases; JSON is the universal format of APIs and applications. Converting between them is one of the most common data-wrangling tasks there is.
The conversion takes the first row as field names and turns every subsequent row into an object, producing an array of objects - the shape almost every API and JavaScript application expects.
Key takeaways
- The first row becomes the object keys.
- Fields containing commas, quotes or newlines must be quoted in the CSV.
- A doubled quote inside a quoted field represents one literal quote.
- Everything in CSV is a string - type information is lost on export.
- Regional settings mean some spreadsheets export semicolons rather than commas.
How the conversion works
name,age,city
Ada,36,London
Grace,45,New York
JSON output:
[
{"name": "Ada", "age": "36", "city": "London"},
{"name": "Grace", "age": "45", "city": "New York"}
]
Why CSV parsing is harder than splitting on commas
The naive approach - split each line on commas - breaks on real data almost immediately. CSV has quoting rules that exist precisely because the delimiter can appear inside the data.
| CSV | Correct interpretation | Naive split gives |
|---|---|---|
| a,b,c | Three fields | Correct |
| "Smith, John",42 | Two fields | Three fields - wrong |
| "She said ""hi""",1 | Two fields, one containing a quote | Mangled |
| "line one line two",2 | Two fields, one with a newline | Two broken rows |
| a,,c | Three fields, middle empty | Correct |
A proper parser tracks whether it is inside a quoted field, which is the only way to handle delimiters and newlines appearing within data.
Delimiters and regional settings
| Delimiter | Name | Where you meet it |
|---|---|---|
| , | Comma | The default in most English-locale exports |
| ; | Semicolon | European locales where comma is the decimal separator |
| \t | Tab | TSV files; safest for data containing commas |
| | | Pipe | Common in data warehousing |
A spreadsheet set to a European locale exports semicolon-separated files by default, because a comma there means a decimal point. This is a very common source of "the file will not import" problems.
Type conversion
CSV has no type system - every field is text. When converting to JSON you have to decide whether to preserve that or infer types, and both choices have costs.
| CSV value | As a string | Type-inferred | Risk of inferring |
|---|---|---|---|
| 42 | "42" | 42 | None usually |
| 007 | "007" | 7 | Loses leading zeros in ID codes |
| true | "true" | true | A literal word "true" becomes a boolean |
| +44 20 7946 | "+44 20 7946" | Could become a number | Phone numbers corrupted |
| 2026-09-14 | "2026-09-14" | Could become a date | Timezone shifts appear |
| 1.50 | "1.50" | 1.5 | Trailing zero lost on prices |
This converter keeps values as strings, which is lossless. Convert types deliberately afterwards, where you know what each column actually means.
Other things that go wrong
- Encoding. A file saved as Windows-1252 rather than UTF-8 turns accented characters into mojibake. Always export and read as UTF-8.
- Byte order marks attach themselves to the first column name, giving you a key like "\ufeffname" that never matches.
- Duplicate column names collapse into one key, silently losing a column.
- Inconsistent column counts between rows, usually from unescaped delimiters in the data.
- Line ending differences - CRLF versus LF - can leave a stray carriage return at the end of the last field on every row.
- Empty trailing lines produce an empty final object.
Frequently Asked Questions
How do I convert CSV to JSON?
Paste your CSV into the tool. The first row is taken as field names and every subsequent row becomes an object, producing an array of objects - the shape most APIs and JavaScript applications expect.
Does it handle commas inside fields?
Yes. Fields containing the delimiter must be wrapped in double quotes in the CSV, and the parser tracks quoted state correctly. This is why a naive split on commas fails on real data - "Smith, John" is one field, not two.
How are quotes inside a field represented?
A literal double quote inside a quoted field is written as two consecutive double quotes. So "She said ""hi""" is a single field containing: She said "hi". This is the RFC 4180 convention.
Why does my CSV use semicolons instead of commas?
Because it was exported from a spreadsheet set to a European locale, where the comma is the decimal separator. Those locales use semicolons as the field delimiter instead. Set the delimiter option to match your file.
Are numbers converted to JSON numbers?
No, values are kept as strings, which is lossless. Automatic type inference corrupts data - it strips leading zeros from postcodes and SKUs, mangles phone numbers and drops trailing zeros from prices. Convert types deliberately afterwards where you know what each column means.
Why do my accented characters look wrong?
Almost certainly an encoding mismatch - the file was saved as Windows-1252 or Latin-1 rather than UTF-8. Re-export it as UTF-8. This is the usual cause of names appearing with strange character sequences.
Can a CSV field contain a line break?
Yes, provided the field is quoted. A proper parser handles this correctly, keeping the multi-line content as a single field. Tools that split the file on newlines before parsing break badly on such data.
Is my data uploaded anywhere?
No. Conversion runs entirely in your browser. Nothing is transmitted or stored, which matters when the spreadsheet contains customer records or other confidential data.