Skip to main content
CalcChef

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

JSON output
Paste CSV to convert

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 cellJSON valueNote
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 cellJSON valueNote
3030a number
-2.5-2.5a number
TRUEtruea 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 rowKeys in the JSON
a,b,c / 1,2,3a | b | c
a;b;c / 1;2;3a | b | c
a⇥b⇥c / 1⇥2⇥3 (tabs)a | b | c
a|b|c / 1|2|3a | 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 rowKeys in the JSON
id,id,idid, id_2, id_3
name,name,name_2name, name_3, name_2
id,id,,name,idid, id_2, col3, name, id_3
a,,ba, 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

  1. Paste CSV into Input CSV, open or drop a .csv, .tsv or .txt file, or press Sample. The tool converts as you type.
  2. Leave the delimiter on Auto-detect, or choose comma, semicolon, tab or pipe.
  3. 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.
  4. 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 tools