CSV to JSON Converter
Convert CSV data to a JSON array of objects instantly
Tip: you can also drag & drop a .csv file onto this box.
This CSV to JSON converter turns comma-, semicolon-, or tab-delimited text into a JSON array of objects. It auto-detects the delimiter, applies RFC 4180 quoting rules, and can infer numbers and booleans from string fields. The output is pretty-printed, copyable, and downloadable, and the whole conversion runs in the browser.
How to Use
- Paste CSV text into the input box or drop a
.csvfile onto it. A dropped file is read and converted automatically. - Choose whether the first row supplies the keys and whether values that look like numbers or booleans should be converted.
- Click Convert to JSON. The detected delimiter appears together with the row and column counts.
- Copy the formatted JSON, or download it as a
.jsonfile.
How the Delimiter Detector Works
Only the first line is examined. The code walks that line character by character, tracks whether it is inside a quoted field, and counts commas, semicolons, and tabs that appear outside quotes. The candidate with the highest count wins; if nothing is found or the count ties, comma is used. Because detection reads just the first line, a file whose first row is a single unquoted value and whose later rows are comma-separated is a case to check by hand — the parser will fall back to comma, which is usually correct, but a file whose first row uses one delimiter and whose data rows use another cannot be detected reliably.
Type Inference in Practice
With inference enabled, the converter checks each field against a small set of patterns. Everything unmatched, including empty strings, stays a string:
| Raw field | Converted to | Why |
|---|---|---|
42 | 42 (number) | integer pattern |
-7 | -7 (number) | negative integer pattern |
3.14 | 3.14 (number) | decimal pattern |
true / false | true / false (boolean) | literal match |
007 | 7 (number) | leading zeros are dropped |
1e5 | "1e5" (string) | exponent notation not matched |
+5 | "+5" (string) | plus sign not matched |
| (empty) | "" (string) | empty stays empty |
The pattern is deliberately conservative in some ways and careless in others: it will not touch scientific notation, but it will silently strip leading zeros from an identifier.
Worked Examples
A small comma-delimited file with a header and inference on:
name,age,active
Alice,30,true
Bob,25,false
becomes:
[
{ "name": "Alice", "age": 30, "active": true },
{ "name": "Bob", "age": 25, "active": false }
]
The same data with inference off would produce "age": "30", "active": "true", and so on — every value a string.
A semicolon-delimited export with identifier-like values:
id;zip
007;01234
The detector picks semicolon from the first line. With inference on, the result is [{"id":7,"zip":1234}], which is almost certainly wrong for IDs. With inference off, it is [{"id":"007","zip":"01234"}] — the correct choice for this kind of column.
Edge Cases and Common Mistakes
- Leaving inference on for ID columns. ZIP codes, phone numbers, and zero-padded IDs all lose their leading zeros. This is the single most common surprise with the tool.
- Relying on the header being present. If you leave the header toggle on but the file has no header, the first data row is consumed as keys. If the file has a header and you turn the toggle off, that row is duplicated into the data.
- Expecting extra columns to survive. Fields beyond the header’s column count are discarded, not appended, so a ragged file silently loses trailing data.
- Assuming quotes are always special. A quote only starts a quoted field at the beginning of a field; a quote in the middle is kept literally. Files produced by some tools rely on this, so the behavior is intentional.
- Treating a trailing newline as a row. A single trailing line ending does not create an extra empty object, but a genuinely blank line in the middle of the file does produce a row with a single empty string.
Practical Scenarios
The converter fits best when you need structured data quickly and do not want to write a parsing script. Common uses include turning a spreadsheet export into a JSON array for an API request, preparing seed data for a database, building fixtures for tests where you want exact control over which fields are strings and which are numbers, and simply reading an unfamiliar export in a more legible shape. It is also handy for one-off data cleaning: paste the file, toggle inference off, and the output preserves every value exactly as written so you can inspect what the source actually contains.
Working With Large or Unusual Files
Parsing is a single pass, but the whole text and the resulting array are held in memory, so multi-megabyte files can be slow or run into browser memory limits. Very large exports are usually better processed with a streaming parser. Watch for a UTF-8 byte order mark at the start of files saved by Excel: the BOM can end up attached to the first header key, so a column named name may show up as \ufeffname. Re-saving as UTF-8 without a BOM, or removing the first character, fixes it. Only UTF-8 input is handled — other encodings are not converted, so accented characters may arrive already mangled. And because delimiter detection reads the first line alone, a file whose first row uses one separator and whose data rows use another cannot be split correctly; set the data aside and normalize it before converting.
Related Tools
Frequently Asked Questions
Which delimiter wins when the first line contains several commas, semicolons, and tabs?
The detector counts each candidate on the first line only, ignoring characters inside quoted fields, and keeps the one with the highest count. Ties are resolved in favor of comma because commas are checked first, so a file with equal commas and semicolons is treated as comma-delimited. Comma is also the fallback when no candidate appears at all.
Does type inference convert scientific notation or a leading plus sign?
No. Inference only matches the pattern -?digits with an optional decimal part, so "42" and "3.14" become numbers but "1e5", "+5", and "3." stay strings. If your column contains those forms, the safest choice is to switch inference off and convert them yourself after inspecting the JSON.
Why did my leading-zero ZIP codes lose their zeros?
Type inference is on by default, and "01234" matches the number pattern, so it becomes 1234. The same happens to "007", which becomes 7. Turn inference off whenever a column holds ZIP codes, phone numbers, account numbers, or other identifier-like values, and every field will stay a string exactly as written.
What happens to a quote that appears in the middle of an unquoted field?
A double quote only opens a quoted field when it appears at the very start of that field. Anywhere else the quote is kept as a literal character, so a value like 12" pipe is preserved instead of swallowing the rest of the line. Quoted fields that begin with a quote still follow RFC 4180 rules, including doubled quotes as literal quotes.
How are rows with the wrong number of columns handled?
Short rows are padded with empty strings so every object ends up with the same keys. Extra fields beyond the number of header columns are dropped, so make sure the header row describes the widest row in the file. With the header toggle off, keys are generated as column_1, column_2, and so on.
What does turning the header toggle off do?
The first row stops being treated as keys and becomes data instead. Every row is converted into an object keyed column_1, column_2, and so on, and the row count includes what used to be the header. This is useful for headerless files such as plain numeric grids.
Reviewed by the HandyTools Hub team · Last updated