CSV to JSON
CSV · TSV · JSON · JSON Lines
Paste CSV in the first box.
Table preview

Your data appears here as a table.

How the conversion works

CSV

name,address.city,age,zip,tags
Ana,Lisbon,31,01100,"[""a"",""b""]"
"Lee, Jo",Seoul,,04524,[]

JSON

[
  { "name": "Ana",
    "address": { "city": "Lisbon" },
    "age": 31, "zip": "01100",
    "tags": ["a", "b"] },
  { "name": "Lee, Jo",
    "address": { "city": "Seoul" },
    "age": "", "zip": "04524",
    "tags": [] }
]

CSV to JSON

  • The first row gives the names of the fields. Empty names become column_3, and a repeated name gets a number (name_2), so no value is lost.
  • Numbers, true/false and null become real JSON values. Values with a leading zero (01100), a plus sign or more than 15 digits stay text, because they are codes, not amounts. A cell that holds a JSON array or object, such as ["a","b"], is read as JSON.
  • A header with a dot, such as address.city, makes a nested object. Turn "Nested keys" off to keep the dot in the key name.
  • Empty cells become "", null or no key at all, as you choose. Empty lines are skipped.
  • A row with more or fewer cells than the header is still converted, and the status line tells you which lines they are.

JSON to CSV

  • The input can be an array of objects, an array of arrays, one object, an object whose values are objects (each one becomes a row, with its name in a key column), or JSON Lines (one object per line). If the array sits inside a wrapper such as {"data": [...]}, it is found.
  • Every key that appears in any object becomes a column, in the order it first appears. Missing values give empty cells.
  • Nested objects become a.b columns; arrays are written as JSON text in one cell. null gives an empty cell.
  • Numbers are written exactly as they are in your JSON, so 12345678901234567890 and 1.50 do not change.

The CSV format in short (RFC 4180)

CSV has no single official standard, but RFC 4180 describes what almost every program reads and writes:

  1. Each record is one line. Fields are separated by a comma (or another delimiter).
  2. A field that contains the delimiter, a double quote or a line break is put in double quotes: "Lee, Jo".
  3. A double quote inside a quoted field is written twice: "She said ""hi""" means She said "hi".
  4. A quoted field may contain line breaks, so one record can cover several lines of the file.
  5. Spaces belong to the field. a, b gives the second field " b" with a space in front.

TSV (tab-separated values) is the same idea with a tab between fields; it is what you get when you copy cells from Excel or Google Sheets. JSON Lines (also called NDJSON) puts one JSON object on each line, which is common for logs and for large exports, because a program can read it line by line.

CSV files and Excel: common problems

ProblemWhyFix
All data in column AExcel in many European countries expects semicolons, because the comma is the decimal mark.Download with the semicolon delimiter, or use Data > From Text/CSV.
São Paulo instead of São PauloWithout a byte order mark, Excel reads the file in the old Windows code page.Keep UTF-8 BOM for Excel on when you download.
ZIP code 01100 shows as 1100Excel turns everything that looks like a number into a number.Import with Data > From Text/CSV and set the column type to Text.
Long IDs show as 1.23457E+19Excel keeps only 15 significant digits.Same as above: import the column as Text.
A cell runs a formulaCells that start with =, +, - or @ are read as formulas (CSV injection).For data from other people, turn on Protect against formulas: such text cells get a leading '.

Convert CSV and JSON in code and on the command line

ToolCSV to JSONJSON to CSV
Pythonrows = list(csv.DictReader(open('data.csv', newline='', encoding='utf-8')))
json.dump(rows, open('data.json', 'w'), indent=2)
(all values stay strings)
w = csv.DictWriter(f, fieldnames=rows[0].keys())
w.writeheader(); w.writerows(rows)
pandaspd.read_csv('data.csv').to_json('data.json', orient='records', indent=2)pd.json_normalize(data).to_csv('data.csv', index=False) (nested keys become a.b columns)
JavaScript (Papa Parse)Papa.parse(text, { header: true, dynamicTyping: true }).dataPapa.unparse(rows)
PowerShellImport-Csv data.csv | ConvertTo-Json | Set-Content data.jsonGet-Content data.json -Raw | ConvertFrom-Json | Export-Csv data.csv -NoTypeInformation
Millermlr --icsv --ojson cat data.csvmlr --ijson --ocsv cat data.json (flattens nested keys with a dot)
jq—jq -r '(.[0] | keys_unsorted) as $k | $k, (.[] | [.[$k[]]]) | @csv' data.json
csvkitcsvjson data.csv > data.jsonin2csv data.json > data.csv

Splitting a line on every comma (line.split(',')) is the most common CSV bug: it breaks as soon as a field contains a quoted comma or a line break. Use a real CSV parser, like the ones above or this page.

Frequently asked questions

How do I convert a CSV file to JSON?

Choose "CSV to JSON", then paste the CSV text or click "Open file". The first row is used as the names of the fields, and every other row becomes one JSON object. The delimiter (comma, semicolon, tab or pipe) is found automatically. Copy the JSON or download it as a .json file.

How do I convert JSON to CSV or open JSON in Excel?

Choose "JSON to CSV" and paste an array of objects, such as [{"name": "Ana", "age": 31}]. Every key becomes a column. Turn on "UTF-8 BOM for Excel" and click Download: Excel then opens the file with the right accents and columns. If your Excel uses a comma as the decimal mark (most of Europe), choose the semicolon as the delimiter.

Why is 00123 kept as text and not turned into a number?

A value with a leading zero is usually a code, such as a ZIP code, a phone number or a product number, not an amount. Turning it into the number 123 would lose information, so it stays a string. Very long whole numbers (more than 15 digits, such as IDs and card numbers) also stay strings, because JavaScript and many other languages cannot store them exactly as numbers.

What happens to nested JSON objects and arrays?

With "Flatten nested objects" on, an object inside an object becomes columns with a dot in the name: {"address": {"city": "Lisbon"}} gives the column address.city. Arrays are written as JSON text in one cell, for example ["red","blue"]. The other direction works too: in CSV to JSON, turn on "Nested keys from a.b headers" and the column address.city becomes a nested object again.

My CSV uses semicolons instead of commas. Will it work?

Yes. Excel in countries that write decimals with a comma (Germany, France, Spain, Brazil and many more) saves CSV files with semicolons. The converter looks at the first rows and picks the delimiter that gives the same number of columns on every line: comma, semicolon, tab or the pipe character. You can also choose it yourself.

Why do accents look wrong when I open a CSV in Excel?

Excel opens a CSV file in the old Windows code page unless the file starts with a UTF-8 byte order mark (BOM). Then "São Paulo" shows as "São Paulo". Downloads from this page include the BOM when "UTF-8 BOM for Excel" is on. When you open a file here, it is read as UTF-8, and if that fails, as Windows-1252, the code page older Excel versions use.

Is my data uploaded?

No. The file is read and converted by JavaScript in your browser, and nothing is sent to a server, so you can use it for customer lists and other private data. Only your settings, such as the delimiter and the indent, are kept in this browser for your next visit.

More developer tools