How to convert CSV to JSON, and back
- Choose CSV to JSON to turn spreadsheet data into JSON, or JSON to CSV to go the other way.
- Paste your data into the left box, or press Open a file (or drag a file onto the box). A file can be up to 10 MB. The result updates as you type.
- Check the table under the boxes. It shows how your CSV was read, so a wrong separator or a shifted column is obvious before you copy anything.
- Press Copy result or Download. Use result as input flips the direction so you can check that a round trip returns what you started with.
What CSV and JSON are
CSV (comma-separated values) is a plain text table: one row per line, and the cells of a row separated by a comma or another separator. Spreadsheets, databases and many web services can export it. JSON is the format that programs and web services pass around: it holds text, numbers, true or false, null, lists and objects with named values, and the objects can contain other objects. Converting CSV to JSON gives every row a set of named values, usually using the first row as the names. Converting JSON to CSV does the opposite and has to squeeze possibly nested data into a flat table.
The CSV to JSON options
- Separator. Auto-detect looks at the first lines and picks the comma, semicolon, tab or pipe that gives the same number of columns on every line, ignoring separators inside quotes. If a file is unusual, choose the separator yourself.
- First row is the column names. On, the result is a list of objects such as
nameandcitywith a value for each. Off, it is a list of lists, one per row, and the first row is treated as data. - Convert numbers and true/false. On, a cell that holds 42 or 9.5 becomes a JSON number, and true or false becomes a JSON boolean. Everything else stays text. A cell is only converted when no digits would be lost, so a code like 00501, a phone number or an id longer than 15 digits stays text. JavaScript cannot hold whole numbers above 9,007,199,254,740,991 exactly, which is why large ids are safer as text.
- Empty cells as null. Off, an empty cell becomes an empty string. On, it becomes null, which many programs treat as “no value”.
- Trim spaces. Removes spaces at the start and end of every cell and column name, which fixes values such as
" Lisbon"from files exported with a space after each comma. - Nest columns named a.b. A column called
city.namebecomes anameinside acityobject. If one column is calledcityand anothercity.name, they cannot both be built, so the second keeps its flat name and the page says so. - Output. Formatted adds line breaks and indents, compact removes all spaces, and “Line per row” writes one JSON object on each line, the form called JSON Lines, which is easy to process one row at a time.
Quotes, line breaks and other awkward cells
A cell that contains the separator, a line break or a quotation mark has to be wrapped in double quotes, and a quote inside such a cell is written as two quotes. For example, "Likes ""tea"", not coffee" is the text Likes "tea", not coffee. The converter follows these rules, so a cell can hold commas and even several lines. A byte order mark at the start of the file, which some programs add, is ignored. If a quote is never closed, or text follows a closing quote, the page names the line where the problem is instead of producing wrong data.
Rows with a different number of cells than the header are still converted, and the page lists them: missing cells become null, and extra cells get names like “column 6”. Two columns with the same name get a number added to the later one, and an empty column name becomes “column 3” and so on, so that no value is lost.
JSON to CSV
The best input is a list of objects, each of which becomes a row. The columns are all the names found in any object, in the order they first appear, and an object that lacks a name gets an empty cell. A single object becomes one row, a list of lists becomes rows with numbered columns, and a list of plain values becomes one column called “value”. A mix of objects and plain values is reported as an error, because it cannot be a table.
- Flatten nested objects writes an object inside an object as columns with dotted names, such as
city.name. Untick it to keep a nested object as one cell of JSON text. - Lists inside an item are written into one cell as JSON text, because there is no fixed number of columns for them.
- Quoting is added only where needed: around cells that contain the separator, a quote or a line break, or that start or end with a space.
- Separator and line breaks. Use a semicolon if the file will be opened in a spreadsheet set up for a decimal comma. Windows line breaks (CRLF) are what RFC 4180, the closest thing CSV has to a standard, describes, and some older programs expect them.
- Protect against spreadsheet formulas adds a ’ in front of text that starts with =, +, - or @. A spreadsheet treats such a cell as a formula, which is a known risk when a file built from untrusted data is opened (it is called CSV injection). The option changes those values, so use it only for files that people will open in a spreadsheet.
Common problems
- Everything lands in one column. The separator is wrong. Try another one in the list.
- Accented letters look wrong in a spreadsheet. The file is UTF-8 text, and some versions of Excel guess a different encoding when you double-click a file. Use the import command (Data, then From Text/CSV) and choose UTF-8.
- A number lost its zeros or turned into a date. That happened in the spreadsheet before the file reached this page. Keep the column as text when you export or import.
- JSON that will not convert. Check it with the JSON formatter, which reports the position of the first error. To compare the result with an earlier version, use the text compare tool.
Your data stays on your device
Many converters upload the file to a server. This page does not: reading, converting and writing all run in your browser, so a customer list or a database export is never sent anywhere. Because such data is often personal, the page does not keep it either. Only your settings are remembered on this device, and a reload starts with empty boxes.
Frequently asked questions
Why did my zip code or ID keep its leading zeros as text?
On purpose. A value such as 00501 is a code, not a quantity, and writing it as the number 501 would lose the zeros for good. The converter only turns a cell into a JSON number when writing it back gives the same digits, so codes with leading zeros, phone numbers and very long ids (more than 15 digits) stay text. If you want everything as text, untick “Convert numbers and true/false”. If the zeros were already gone in the file you pasted, usually because a spreadsheet dropped them, they cannot be recovered here.
How is nested JSON written as CSV?
With “Flatten nested objects” ticked, an object inside an object becomes extra columns named with dots, so {"city": {"name": "Lisbon"}} gives a column called city.name. Lists inside an item, such as tags, are written into one cell as JSON text like ["a","b"], because a list has no fixed number of columns. Untick the option to keep every nested object as one cell of JSON text. Going the other way, tick “Nest columns named a.b” to rebuild the objects.
My CSV ends up in one column, or in the wrong columns. Why?
The file uses a different separator than the program that opened it expects. Many European spreadsheet settings write semicolons because the comma is their decimal mark, and some exports use tabs or pipes. Here, “Auto-detect” compares the first lines and picks the separator that gives the same number of columns on every line, and you can choose one by hand. When you write CSV, pick the separator the program that will open it expects.
What does “Protect against spreadsheet formulas” do?
A spreadsheet treats a cell that starts with =, +, - or @ as a formula, so a value such as =HYPERLINK(…) taken from untrusted data can run when someone opens the file. With the option on, text values that start with one of those characters get a ’ in front, which makes the spreadsheet show them as plain text. It changes those values, so leave it off when the file is for a program rather than a person, and turn it on when untrusted text will be opened in a spreadsheet. Real JSON numbers such as -5 are not changed.
Is my data uploaded?
No. Reading the CSV, converting it and writing the result all run in your browser, so nothing you paste or open is sent to this website or anywhere else. The page remembers only your settings on this device, not your data, because spreadsheets so often hold names, emails and other personal information.
How big a file can I convert?
Files up to 10 MB can be opened. The work happens on your own device, so the time depends on how fast it is, and a file near the limit takes a moment to convert. For larger files, convert the part you need, or use a command line tool.