CSV to JSON
Convert CSV to JSON: the first row becomes the keys, quoted commas and line breaks are kept, and numbers and booleans are detected only if you ask. How it works
Use the CSV to JSON
About the CSV to JSON
The CSV name,age and Ann,30 on the next line becomes [{"name":"Ann","age":"30"}]: the first row gives the keys and every value stays text, so 30 is "30", unless you tick Detect numbers and booleans. This CSV to JSON converter detects a comma, semicolon, tab or pipe from the first line and keeps commas, quotes and line breaks inside a quoted field.
How CSV cells become JSON values
| CSV cell | JSON value | Note |
|---|---|---|
| 007 | "007" | keeps its zeros |
| 1e3 | "1e3" | not turned into 1000 |
| 30 | "30" | a number stays text |
| true | "true" | not a boolean |
| null | "null" | the text null |
| (empty) | "" | an empty cell |
| "x ""y"" z" | "x \"y\" z" | quotes are doubled inside quotes |
With Detect numbers and booleans off, the default, every value is a JSON string.
With Detect numbers and booleans ticked
| CSV cell | JSON value | Note |
|---|---|---|
| 30 | 30 | a number |
| -2.5 | -2.5 | a number |
| TRUE | true | a boolean, any letter case |
| 007 | "007" | leading zeros stay text |
| 1e5 | "1e5" | exponent form stays text |
| .5 | ".5" | no digit before the point |
| -0 | "-0" | negative zero stays text |
| 1234567890123456 | "1234567890123456" | over 15 digits stays text |
| null | "null" | the text null |
| (empty) | "" | an empty cell |
Only a plain decimal with at most 15 digits becomes a number, so no digit is lost; dates stay text.
Which delimiter the first line gives
| First line and one data row | Keys in the JSON |
|---|---|
| a,b,c / 1,2,3 | a | b | c |
| a;b;c / 1;2;3 | a | b | c |
| a⇥b⇥c / 1⇥2⇥3 (tabs) | a | b | c |
| a|b|c / 1|2|3 | a | b | c |
| a,b;c / 1,2;3 (a tie goes to the comma) | a | b;c |
| a;b;c,d / 1;2;3,4 (two semicolons beat one comma) | a | b | c,d |
| "a,b";c / 1;2 (the comma is inside quotes) | a,b | c |
Auto-detect counts commas, semicolons, tabs and pipes outside quotes on the first line only. Choose the delimiter by hand if that line misleads.
How repeated and empty headers are renamed
| Header row | Keys in the JSON |
|---|---|
| id,id,id | id, id_2, id_3 |
| name,name,name_2 | name, name_3, name_2 |
| id,id,,name,id | id, id_2, col3, name, id_3 |
| a,,b | a, col2, b |
A repeat gets _2, _3 and so on, skipping a name already in the header. An empty header becomes col followed by its column number.
How to use this tool
- Paste CSV into Input CSV, open or drop a .csv, .tsv or .txt file, or press Sample. The tool converts as you type.
- Leave the delimiter on Auto-detect, or choose comma, semicolon, tab or pipe.
- Untick First row is headers if the data has no header row; the keys become col1, col2 and so on. Tick Detect numbers and booleans to get JSON numbers and true or false.
- Press Copy and choose formatted JSON, minified JSON or a JavaScript const assignment, or press Download .json.
Frequently asked questions
- Why are all my numbers strings in the JSON?
- By default the tool does not guess types: 30 becomes "30", 007 stays "007" and true stays "true". Tick Detect numbers and booleans and 30 becomes 30 and true becomes true, while 007, 1e5, +1, .5 and numbers over 15 digits still stay text, so a ZIP code or a long ID is not changed.
- How does it detect the delimiter?
- It reads the first line only and counts commas, semicolons, tabs and pipes outside double quotes. The most frequent wins, a tie goes to the comma, and a line with none is read as comma-separated. If the first line is misleading, pick the delimiter from the menu.
- What happens to duplicate or empty headers?
- A repeated header gets a number: id,id,id becomes id, id_2, id_3. An empty header becomes col followed by its column number: a,,b becomes a, col2, b. This stops a later column from overwriting an earlier one.
- What does “CSV row 3 has 1 column; expected 2.” mean?
- Every row must have as many fields as the header. For a,b then 1,2 then 3 the tool stops with “CSV row 3 has 1 column; expected 2.” and counts the header as row 1. The number counts records, not lines: blank lines are skipped and a quoted cell with a line break in it is one record, so it can be lower than the line number in the box. Fix the row, or quote a field that holds a stray delimiter.
- How do I convert CSV with no header row?
- Untick First row is headers. The keys become col1, col2 and so on: 1,2 and 3,4 give [{"col1":"1","col2":"2"},{"col1":"3","col2":"4"}].
- Is my CSV uploaded?
- The conversion runs in your browser and the page does not send the CSV to a server. The last input is kept in this browser’s local storage so it is there on your next visit; Clear Saved Values removes it.
Related Tools
View all toolsJSON to CSV
Turn JSON into CSV: an array of objects, one object or a list of values. Flatten nested objects, expand arrays into rows, then copy or download.
XML to JSON Converter
Convert XML to JSON and JSON back to XML: attributes go under @attributes, repeated elements become arrays, and an XML error shows its line and column.
YAML to JSON Converter
Convert YAML to JSON with anchors and merge keys resolved, YAML 1.2 or 1.1 typing for yes/no, and a warning for numbers JSON cannot hold.
JSON to YAML
Convert JSON to YAML in block or flow style. Text such as yes or 017 is quoted so it stays a string, and a JSON error shows its line and column.
SQL to JSON
Turn SQL INSERT statements, or a result table pasted from psql, MySQL or Markdown, into JSON. Quoted values stay strings; numbers, true and NULL get types.
JSON to SQL
Generate SQL INSERT statements, and CREATE TABLE if you want it, from JSON for PostgreSQL, MySQL, SQLite or SQL Server, with types inferred from every row.