Suggest a tool

CSV to JSON converter & formatter

Paste or upload a CSV and get formatted JSON as you type. Free, online, and your file never leaves your browser.

Delimiter
untitled.csv

The conversion runs in your browser. Your CSV is never uploaded.

Output
Indent
data.json

Your JSON shows up here.

Paste CSV on the left, drop a file, or press Ctrl/Cmd + V anywhere.

waiting for CSV

How to convert CSV to JSON

  1. 1

    Add your CSV

    Paste it into the left box, drop a file on it, or use Upload CSV. The JSON appears on the right as you type.

  2. 2

    Check the options

    The delimiter is detected for you. Say whether the first row is a header, choose objects, arrays or JSON Lines, and pick how the JSON is indented.

  3. 3

    Take the JSON

    Copy it to the clipboard, or Download it as a .json file.

CSV to JSON example

Here is a small file and what comes out with the default settings. The first row became the keys. Miller, Jon kept its comma because it was in quotes, 5 and true came out as a number and a boolean, and the missing email is an empty string.

customers.csv
id,name,email,plan,seats,active
1,Asha Rao,asha@example.com,pro,5,true
2,"Miller, Jon",jon@example.com,free,1,false
3,Lena Fischer,,team,12,true
customers.json
[
  {
    "id": 1,
    "name": "Asha Rao",
    "email": "asha@example.com",
    "plan": "pro",
    "seats": 5,
    "active": true
  },
  {
    "id": 2,
    "name": "Miller, Jon",
    "email": "jon@example.com",
    "plan": "free",
    "seats": 1,
    "active": false
  },
  {
    "id": 3,
    "name": "Lena Fischer",
    "email": "",
    "plan": "team",
    "seats": 12,
    "active": true
  }
]

Objects, arrays or JSON Lines

The same two rows in each of the three output formats.

formats.tbl
CSV to JSON output formats
OutputWhat you getGood for
Objects
[{"id":1,"name":"Asha"},{"id":2,"name":"Jon"}]
APIs, config files and most code. Each row is an object keyed by the header.
Arrays
[["id","name"],[1,"Asha"],[2,"Jon"]]
Charts, tables and smaller files. The header is the first row, and no key is repeated.
JSON Lines
{"id":1,"name":"Asha"}
{"id":2,"name":"Jon"}
One record per line, for tools that read data row by row: BigQuery, bulk imports, logs.

How headers, delimiters and types are handled

Headers
The first row gives the keys. Untick First row is the header and the columns are named column_1, column_2 and so on. A column with no name gets the same kind of name, and a repeated name gets a number: name, name_2.
Delimiters
Commas, semicolons, tabs and pipes are detected from the first rows. Excel writes semicolons in much of Europe, and you get tabs when you copy cells out of a spreadsheet. Pick the delimiter yourself if the guess is wrong.
Quotes and line breaks
A value in double quotes can hold the delimiter, line breaks, and quotes written twice (""). That's RFC 4180, the rules most programs follow when they write CSV.
Numbers and booleans
42 and 3.14 become numbers; true, false and null become the JSON values. Anything with a leading zero (007, 02108), a plus sign, an exponent or more than 15 digits stays text, so ZIP codes, phone numbers and long IDs aren't changed.
Empty cells
An empty cell becomes "". You can turn it into null or leave the key out of that row. Blank lines are skipped.
Mismatched rows
A row with too few values is filled with empty cells; extra values get numbered names. Each such row is listed under the result with its line number, so you can check it.

CSV to nested JSON

CSV is flat, but column names can describe a shape. Turn on Nest keys on dots and address.city becomes a city key inside an address object. Numbered parts such as tags.0 and tags.1 become a list.

users.csv
id,user.name,address.city,tags.0,tags.1
1,Asha Rao,Pune,admin,beta
users.json
[
  {
    "id": 1,
    "user": {
      "name": "Asha Rao"
    },
    "address": {
      "city": "Pune"
    },
    "tags": [
      "admin",
      "beta"
    ]
  }
]

Convert CSV to JSON in code

For a script or a data pipeline, these do the same job as the tool above.

python
import csv, json

with open("data.csv", newline="", encoding="utf-8-sig") as f:
    rows = list(csv.DictReader(f))

with open("data.json", "w", encoding="utf-8") as f:
    json.dump(rows, f, indent=2, ensure_ascii=False)

Python's standard library is enough. DictReader uses the first row as keys, and utf-8-sig drops the invisible mark Excel puts at the start of a file. Every value comes out as text.

python, with pandas
import pandas as pd

pd.read_csv("data.csv").to_json("data.json", orient="records", indent=2)

With pandas it's one line, and numbers and booleans keep their types.

javascript (node)
import fs from "node:fs";
import Papa from "papaparse"; // npm install papaparse

const csv = fs.readFileSync("data.csv", "utf8");
const { data } = Papa.parse(csv, { header: true, dynamicTyping: true, skipEmptyLines: true });

fs.writeFileSync("data.json", JSON.stringify(data, null, 2));

In JavaScript, Papa Parse handles quotes and line breaks correctly, in Node and in the browser. dynamicTyping turns numbers and booleans into real ones.

command line (jq)
jq -R -s 'split("\n") | map(select(length > 0) | split(","))
  | .[0] as $keys | .[1:]
  | map([$keys, .] | transpose | map({(.[0]): .[1]}) | add)' data.csv > data.json

jq can do it without installing anything else, but only for simple files: it splits on every comma, so it breaks on quoted values like "Miller, Jon".

Questions

How do I convert a CSV file to JSON?

Paste the CSV into the box, drop the file on it, or use Upload CSV. The first row becomes the keys and every other row becomes one JSON object. Then copy the result or download it as a .json file. There's nothing to install and no sign-up.

How do I format or pretty-print the JSON?

Pick an indent above the result: 2 spaces, 4 spaces or tabs for readable, formatted JSON, or Minify for the smallest file. The output is reformatted at once; you don't have to convert again.

Does the first row have to be a header?

No. Untick “First row is the header” and the columns are named column_1, column_2 and so on. Or choose Arrays to get every row as a plain list of values.

My CSV uses semicolons or tabs. Will it work?

Yes. Commas, semicolons, tabs and pipes are detected automatically from the first rows, and you can set the delimiter yourself. Tab-separated text copied straight from Excel or Google Sheets works too.

Can it create nested JSON from a CSV?

Yes. Turn on “Nest keys on dots”. A column called address.city becomes a city key inside an address object, and columns such as tags.0 and tags.1 become a list.

Why are some of my numbers in quotes?

Values that only look like numbers are kept as text on purpose: anything with a leading zero (007, 02108), a plus sign, an exponent, or more than 15 digits. That keeps ZIP codes, phone numbers and long IDs exactly as they were. To keep every value as text, untick “Detect numbers and booleans”.

What is JSON Lines, and when should I use it?

JSON Lines (also called NDJSON) puts one JSON object on each line instead of wrapping them all in an array. Tools that read data one record at a time expect it, such as BigQuery, the Elasticsearch bulk API and model fine-tuning files.

Is my CSV uploaded anywhere?

No. The conversion runs in your browser, so what you paste or upload is never sent to our server and nothing is stored. It's gone when you close the tab.

How big a file can it convert?

You can upload files up to 20 MB. For a large result the page shows only the first part on screen to stay fast; Copy and Download always give you all of it.

More free developer tools