CSV to JSON
Last updated: 1 October 2026
Read a CSV table back into an array of JSON objects. The header row supplies the keys, the RFC 4180 quoting is understood on the way in, and type detection is yours to switch on — all inside your browser, so the table never leaves the machine.
What the conversion does
CSV carries its column names in the first line, so the conversion is a direct mapping: the header cells become property names and each following line becomes one object in an array. The table
id,name
1,Ada
2,Grace
becomes [{"id":"1","name":"Ada"},{"id":"2","name":"Grace"}]. Note that the values are strings — that is the default, and the next section explains why.
The header row is the schema
The first line is taken as the header, not as data. Two edge cases are handled rather than left to surprise you:
- Duplicate names — a repeated header is made unique, so
a,abecomesaanda_2. Without this, the second column would silently overwrite the first. - Empty names — a blank header cell is named by position,
column 1,column 2, and so on, so no key is an empty string.
Type detection is off by default — on purpose
CSV has no types. Every cell is text, and the file gives no way to tell a number from a code that happens to be digits. That is why detection is opt-in: left off, every value stays a string, which is the faithful reading of the file.
Switching it on converts only what is unambiguous. A value is treated as a number when it could be written as a JSON number — an optional minus sign, digits, an optional fraction and an optional exponent — and true, false and null are recognised as themselves. Crucially, a value with a leading zero is not converted, because 007 and 02139 are almost always identifiers: ZIP codes, phone numbers, account numbers, product SKUs. A blanket "make it a number" would quietly turn 007 into 7 and corrupt the data; this rule does not.
Quoted fields, embedded commas and line breaks
Reading follows RFC 4180, the same rule the JSON to CSV page writes by. A field wrapped in double quotes may contain the delimiter, a newline, or a pair of double quotes that reads back as one. So "Ada, Countess" is a single value containing a comma, and a value that spans two physical lines stays one cell. Both CRLF and LF line endings are accepted, and a leading UTF-8 byte-order mark — the invisible U+FEFF that Excel and some exporters add — is stripped, so the first column name does not come out as id.
Ragged rows
Hand-edited files rarely have a clean rectangle of cells. A row with fewer fields than the header is padded with empty values and one with extras is truncated, so every object ends up with the same keys. The alternative — rejecting the whole file — is less useful than returning the rows that are well-formed, but it does mean the missing values are genuinely absent.
Frequently Asked Questions
How does CSV map onto JSON objects?
The first row is read as the header and its cells become the property names; every row after it becomes one object in an array, keyed by those names. A CSV with the header id,name and one row 1,Ada produces [{ "id": "1", "name": "Ada" }].
Why are my numbers and booleans coming out as strings?
Type detection is off by default, which is deliberate. CSV has no types, so the converter cannot know whether 007 is the number seven or the code zero-zero-seven; guessing wrong silently corrupts identifiers such as ZIP codes, phone numbers and account ids. Turn on detection when you know the columns are numeric, and even then a value with a leading zero stays a string.
What exactly counts as a number when detection is on?
Only text that a JSON number could be written as: an optional minus sign, digits with no leading zero unless the value is exactly 0, an optional fractional part, and an optional exponent. true, false and null are also recognised. Everything else, including 007 and 1,234, stays a string.
How are quoted fields, embedded commas and line breaks read?
Parsing follows RFC 4180: a field wrapped in double quotes may contain the delimiter, a newline or a doubled double quote, which reads back as a single quote. So a cell holding Ada, Countess is written as "Ada, Countess" and a value spanning two lines stays one field. Both CRLF and LF line endings are accepted.
My file has a UTF-8 BOM; will the first column name break?
No. A leading byte-order mark — the invisible U+FEFF that some tools, Excel among them, put at the start of a CSV — is stripped before parsing, so the first header would otherwise read as id. Here it reads as id.
What happens to rows that do not match the header?
A row with fewer fields than the header is padded with empty values and a row with more is truncated, so every object has the same keys. Ragged rows are common in hand-edited files and are tolerated rather than rejected, but the missing data is genuinely absent from the output.
Want the other direction? JSON to CSV writes an array of objects out as a table. Spotted a bug? Get in touch.