CSV to JSON
Values stay text, so 007 is still 007.
The short answer
Parsed character by character rather than split on commas, because a split on commas is wrong the moment a field contains one. Values arrive as strings on purpose: a CSV has no types, and turning "007" into the number 7 is the single most common way this conversion loses data.
Parsed character by character rather than split on commas, because a split on commas is wrong the moment a field contains one. Quoted fields, doubled quotes and Excel's semicolons all work.
The formula
first row becomes the keys, every later row becomes an object
Worked examples
- "one, two",three
- two fields, not three
- "say ""hi"""
- one field: say "hi"
- 007
- stays the text 007
Reference table
| In the CSV | Means | A split on commas gives |
|---|---|---|
| "one, two" | One field | Two fields |
| "say ""hi""" | say "hi" | Broken quotes |
| A newline inside quotes | One field, two lines | A ragged row |
| Semicolons, not commas | One field per semicolon | One giant field |
How to use it
- 01Paste the CSVFirst row is the header. Nothing is uploaded.
- 02Pick the separatorComma, semicolon or tab. Excel uses semicolons in much of Europe.
- 03Copy the JSONAn array of objects, one per row, formatted with two spaces.
Also searched for
Searches that land here include csv to json, convert csv to json, csv json converter, csv to array and parse csv online.
Parsing a CSV properly
There is no CSV standard, only conventions
RFC 4180 describes the common case and nothing enforces it. Files arrive with semicolons instead of commas, tabs instead of either, CRLF or LF line endings, a byte order mark at the front, and quoting applied inconsistently. A parser has to cope with the file it is given rather than the one it wanted.
Quoting is the whole difficulty
A field is quoted when it contains a delimiter, a quote or a newline. Inside a quoted field, a literal quote is written twice. Both rules are simple and both are invisible to anything that splits on the delimiter, which is why the naive version works on your test file and breaks on real data from a spreadsheet.
Semicolons and the decimal comma
Excel writes CSV using the list separator from your locale. Where the comma is the decimal separator — most of continental Europe — that separator is a semicolon, so a file exported in Berlin looks like one enormous field to a parser expecting commas. That is what the separator buttons are for.
Questions people ask
Why are my numbers strings?
Because a CSV has no types and guessing them loses data. The obvious casualty is a leading zero: 007 becomes 7, and so do postcodes, phone numbers, product codes and any id that happens to be numeric. Convert deliberately on your side, where you know which columns are actually numbers.
What if a field contains a comma?
Then it will be in quotes in the CSV, and this handles it. That is the whole reason for a real parser: "one, two",three is two fields, and any tool that splits on commas reports three. Doubled quotes inside a quoted field work too, and so do newlines inside one.
Why does it say my rows do not all match?
Because a row has more or fewer fields than the header, which almost always means an unclosed quote somewhere above. One missing closing quote swallows every comma and newline after it until the next quote appears, so the error is usually earlier in the file than the row it is reported on.