How to Convert CSV to JSON
Paste CSV, choose the matching delimiter and decide whether the first row contains headers. Preview the JSON array before copying it. Correct quoting is essential when fields contain delimiter characters or line breaks.
CSV Headers and JSON Object Keys
Header cells become object keys. Use distinct headers to avoid ambiguous mappings. Without a header row, generated column names let the converter preserve positions. Review unexpected blank or duplicate headers in the source.
Quoted Fields, Delimiters and Empty Values
Quoted delimiters belong to a field rather than splitting it. A quote inside a quoted field is written twice. Empty cells are represented as null; inspect missing trailing cells and rows with inconsistent field counts.
CSV to JSON Examples
A header id,name followed by 1,Ada produces one record with id and name fields. Numeric and boolean fields are coerced when recognized; leading-zero identifiers remain strings. Pipe-separated values use an array convention. Review inferred types before using the result.
Cleaning CSV Before Conversion
Check delimiter choice, line endings, extra header rows and repeated field names before conversion. Preserve a copy of the original CSV so a cleanup step can be reversed. CSV is text, not an Excel workbook.
More examples and technical details
How the Header Row Becomes Object Keys
Converting CSV to JSON is mostly a mapping exercise. The first line of the file is read as a list of column names, and every following line becomes one object whose keys are those names and whose values are the fields in matching positions. An array of those objects is the output.
This is why the header row carries so much weight. It is the schema of the file, and any oddity in it propagates into every single record. Column names with spaces, trailing whitespace, or mixed casing all become awkward object keys, so it is worth trimming and normalising them before the conversion rather than fixing thousands of objects afterwards.
If the header uses dot notation, unflattening can rebuild nested structure: a column called address.city puts city inside an address object instead of creating a literal key with a full stop in it. That is what makes a JSON to CSV to JSON round trip come back to where it started.
Side by Side Example
A small inventory export, converted with type inference and unflattening turned on.
CSV input
JSON output
Two details are worth noticing. The quoted title in row two keeps its comma and loses its quotes, because the quotes were transport syntax rather than content. And 24.50 became 24.5, because JSON numbers have no concept of trailing decimal places.
Type Inference and When to Skip It
Every value in a CSV file is text. Type inference is the step that decides which of those text values should become JSON numbers, booleans, or null.
| Cell content | Inferred as | Risk |
|---|---|---|
| 42 | Number | Low, unless it is a zero padded code |
| 3.14 | Number | Low |
| 007 | String if padding is preserved | High, inference may strip to 7 |
| true / false | Boolean | Low, but TRUE and yes need explicit rules |
| (empty) | null or empty string | Ambiguous, an empty string and a missing value are not the same thing |
| 1e5 | Number 100000 | Product codes and batch ids get mangled |
| +441234 | String or number | Leading plus is dropped by many parsers |
There is a real argument for leaving everything as strings. Identifiers, phone numbers, postcodes, account numbers, and version strings are all data that looks numeric but must never be arithmetic. If the JSON is going straight into a system that will validate and cast it anyway, strings in and strings out is the safest default. Turn inference on when the JSON is being consumed directly by application code that expects real numbers.
Quoted Fields, Delimiters, and Embedded Newlines
A correct CSV parser is a small state machine, not a call to split. It has to track whether it is currently inside a quoted field, because inside quotes the delimiter and the line break are ordinary characters.
One record spanning three physical lines
That file has four physical lines but only two records. A doubled quote inside a quoted field means a literal quote character, so "He said ""no""" holds the value He said "no". Anything that splits on the newline before understanding quotes will produce three broken rows and no error message.
Header and Row Edge Cases
| Edge case | What goes wrong | Sensible handling |
|---|---|---|
| Duplicate header names | The later column silently overwrites the earlier one | Suffix duplicates as name, name_2, name_3 |
| Empty header cell | Produces an object key of empty string | Fall back to column_1, column_2 by position |
| Ragged row, too few fields | Missing keys, uneven objects | Pad with null so every object has the same shape |
| Ragged row, too many fields | Extra values have no key | Collect the surplus into an _extra array or reject the row |
| Blank line in the middle | Emits an object of all nulls | Skip empty lines by default |
| Comment lines starting with # | Parsed as data | Enable a comment prefix option before parsing |
| CRLF versus LF endings | Trailing carriage return glued onto the last field | Normalise line endings before splitting |
The Byte Order Mark Bug
This one deserves its own section because it wastes more time than anything else on the list. Files exported from Excel on Windows often begin with a UTF-8 byte order mark, three invisible bytes (EF BB BF) before the first character. Most editors hide it. Your parser does not.
What you see and what you get
The symptom is unmistakable once you know it: only the very first column comes back undefined and every other column is fine. The fix is to strip a leading U+FEFF from the file before parsing, or to decode the file with an encoding that consumes the mark. If you are producing files for Excel rather than consuming them, the reverse applies, since Excel needs that mark to recognise UTF-8 at all.
Once your CSV is clean JSON, the next step is usually a schema or a type. Browse the full converter collection for JSON to TypeScript to generate interfaces from the result, JSON Schema for validation rules, and JSON to CSV when you need to send the data back the other way.
Frequently asked questions
How do I convert CSV to JSON?
Paste CSV, choose its delimiter and header behavior, then copy the JSON array.
Does the converter support quoted commas?
Yes. Properly quoted commas are treated as part of the field.
Can I use a custom delimiter?
Choose one of the available delimiter settings, such as comma, semicolon or tab, to match the file.
How are empty cells represented?
Empty cells become null; review irregular rows before using the result.
Is CSV data uploaded?
No. Input is processed in this browser tab and is not uploaded by the tool. Copy and download are actions you control; ordinary page analytics do not receive tool input.