FormatterHQ

CSV to JSON Converter

Turn a CSV file into an array of JSON objects keyed by the header row. Numbers and booleans can be typed automatically, and dotted headers can become nested objects.

Input CSV
Output JSON
Ready.

How to use the CSV to JSON Converter

  1. Paste CSV into the input editor, drop a .csv file on it, use Upload file or Load URL, or click Sample.
  2. Leave Delimiter on Auto-detect or pick comma, semicolon, pipe or tab, and set First row is header and Detect numbers & booleans.
  3. Tick Nest dotted headers if columns such as user.name should become nested objects, then choose an Indent and optionally Sort keys.
  4. Click Convert to JSON; the status bar reports the number of records, or the record where parsing failed.
  5. Copy the JSON or use Download to save it as a file.

Convert CSV to JSON records

This CSV to JSON converter reads a comma-separated (or semicolon-, pipe- or tab-separated) file and returns a JSON array with one object per data row. The header row supplies the property names, so a spreadsheet export becomes something you can feed straight into a JavaScript app, a REST API test or a NoSQL import.

Parsing is done with PapaParse, a well-tested CSV library, so quoted fields, commas inside values and line breaks inside cells are handled the way spreadsheet programs write them.

Example

A small product export with a quoted name and a few tricky values:

sku,name,price,in_stock,zip
001,"Desk lamp, brass",24.50,TRUE,02139
002,Mug,8,false,94107

With the default options the result is:

[
  {
    "sku": "001",
    "name": "Desk lamp, brass",
    "price": 24.5,
    "in_stock": true,
    "zip": "02139"
  },
  {
    "sku": "002",
    "name": "Mug",
    "price": 8,
    "in_stock": false,
    "zip": 94107
  }
]

Notice what typing did. TRUE became a real boolean, prices became numbers, and values with a leading zero stayed strings so that SKU 001 keeps its zeros. The zip column, however, now mixes a string and a number. The next section explains why and how to avoid it.

How values are typed

With Detect numbers & booleans on (the default), each cell is checked against a few strict rules:

  • true, TRUE and True (and the same three spellings of false) become booleans. Words such as yes or ja stay text.
  • Plain decimal numbers such as 42, -0.5 or 1e3 become numbers, as long as they have at most 15 digits.
  • Anything with a leading zero (02139, 007), a plus sign, a thousands separator or a decimal comma (12,50) stays a string.
  • Longer digit strings, such as 16-digit order numbers or card-style IDs, stay strings so no digits are lost to floating-point rounding.

Because the rules work cell by cell, a column can end up with mixed types, as the zip codes above show. Trailing zeros also disappear once a value is a number: 24.50 is written as 24.5. If exact text matters for postal codes, versions or prices, untick the option and every cell stays a string.

Header handling

When First row is header is on, the first record provides the keys. Empty header cells are named after their position (column2), and repeated names get a suffix, so two name columns become name and name_2 instead of overwriting each other. Turn the option off and you get an array of arrays, with the first row treated as data.

Rows shorter than the header are padded with empty strings. Cells beyond the last header column are dropped, which usually points to an unquoted comma inside a value.

Nested JSON from dotted headers

Flat CSV often comes from a tool that flattened JSON first, with headers like user.email or tags.0. Tick Nest dotted headers to rebuild the structure:

id,user.name,user.email,tags.0,tags.1
2,Bo,bo@x.io,green,
[
  {
    "id": 2,
    "user": {
      "name": "Bo",
      "email": "bo@x.io"
    },
    "tags": [
      "green"
    ]
  }
]

Numeric path parts turn into arrays, and empty trailing cells of such a column are removed, so a shorter list does not end with blank strings. This makes the tool a natural round trip for files produced by JSON to CSV.

Indent and key order

Indent sets 2, 3 or 4 spaces or a tab per nesting level. Sort keys puts the keys of every object in alphabetical order, including objects created from dotted headers, while the order of the records themselves is never changed. Leave sorting off to keep the column order of the header row, which is usually what a reader of the JSON expects.

Parsing errors and how to fix them

  • Quoted field unterminated (record N) – a value opens with a double quote that is never closed. Everything after it would be swallowed into one cell, so the converter stops and names the record.
  • Trailing quote on quoted field is malformed – a quote inside a quoted value was not doubled. Write "He said ""hi""" rather than "He said "hi"".
  • Everything lands in one key – the delimiter was guessed wrong, which can happen with very short files. Pick it explicitly in Delimiter.

Record numbers count CSV records, not text lines, so a cell containing line breaks can make them differ from what your editor shows. A leading byte order mark from Excel is removed, and completely empty lines are skipped.

Related tools

To check how a file is split into columns before converting, open it in the CSV viewer. For tab-separated data copied from a spreadsheet, TSV to JSON skips delimiter detection entirely, and the JSON formatter helps when you want to re-indent or validate the result later.

Privacy

The conversion happens in your browser, so the CSV is not uploaded. Only Load URL, which fetches a remote file through our server, and Save & Share, which stores your input for the link, send data to us.

Convert CSV to JSON in Python

csv.DictReader turns each row into a dictionary keyed by the header row, and json.dumps writes the list as JSON. Two defaults surprise people. The csv module returns every value as a string, so 1 becomes "1" unless you convert the column yourself. And json.dumps escapes non-ASCII characters, so Zürich is written as Z\u00fcrich unless you pass ensure_ascii=False. When you read a file, open it with newline="" so that line breaks inside quoted fields are left untouched.

import csv
import io
import json

data = 'id,name,city\n1,Ann,Paris\n2,"Bob, Jr.",Zürich\n'

# for a file: open("data.csv", newline="", encoding="utf-8")
rows = list(csv.DictReader(io.StringIO(data)))
for row in rows:
    row["id"] = int(row["id"])   # csv returns every value as a string

print(json.dumps(rows, indent=2, ensure_ascii=False))

The converter above detects numbers and booleans for you, which makes it a quick way to check what your script should produce.

Frequently asked questions

Why did my zip codes or IDs lose their leading zeros?
They should not: values that start with a zero, such as 02139, are kept as strings even when number detection is on. If a column shows numbers, those cells had no leading zero. Untick Detect numbers & booleans to keep every value as text.
Can I convert a semicolon-separated CSV from Excel?
Yes. Auto-detect recognizes semicolons, and you can also choose Semicolon (;) explicitly. Decimal commas such as 12,50 remain strings because they are not valid JSON numbers.
How do I get a JSON object instead of an array?
The converter always returns an array of records, because a CSV file is a list of rows. If you need a single object keyed by an ID, convert first and then reshape the array in your code.
Is there a size limit?
There is no fixed limit, since everything runs in your browser. Very large files are limited by your device memory and can make the editor slow; in that case turn off Auto update and convert once.
Why does null never appear in the output?
CSV has no way to express null, so empty cells become empty strings. Replace them with null in your code, or post-process the JSON, if your schema needs it.

Last updated October 3, 2026

Related tools