How to convert CSV to JSON
Updated · 3 min read
CSV is the format spreadsheets and databases export; JSON is the format APIs, JavaScript and most modern applications expect. This converter turns each row of a CSV file into a JSON object, using the header row for the property names. It runs in your browser, so you can safely convert exports that contain customer or financial data.
- Paste your CSV into the input box, or drag a
.csvfile onto it. - Check that the first row contains your column names — it becomes the JSON keys.
- If the output looks wrong, set the Input delimiter in Options (comma, semicolon, tab or pipe).
- Choose the JSON indentation, then click Copy or Download.
Example
CSV input
id,name,city,zip,active
1,"Doe, Jane",Boston,02134,true
2,Alex Smith,Rabat,10000,falseJSON output
[
{
"id": 1,
"name": "Doe, Jane",
"city": "Boston",
"zip": "02134",
"active": true
},
{
"id": 2,
"name": "Alex Smith",
"city": "Rabat",
"zip": 10000,
"active": false
}
]Notice three details: the comma inside "Doe, Jane" does not split the field, 02134 stays a string because its leading zero matters, and true/false become real JSON booleans.
Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.
How the conversion works
- Header row → keys. Each column name becomes a property. Blank headers are named
column_1,column_2…, and duplicates get a suffix (email_2) so no column overwrites another. - Each row → one object. The result is a JSON array with one object per data row. Completely empty lines are skipped.
- Types. Plain numbers such as
42or-3.5become numbers;true,falseandnullbecome their JSON equivalents. Everything else stays text. - No silent data loss. Values with leading zeros, hexadecimal or scientific notation, and numbers longer than 15 digits are kept as strings, because converting them to JSON numbers would change them.
- Empty cells become empty strings by default, or
nullwhen Empty cells as null is ticked.
Delimiters, Excel and encodings
Despite the name, many "comma-separated" files are not separated by commas. Excel uses the list separator of the computer's region: in France, Morocco, Germany and much of Europe that is a semicolon, because the comma is the decimal separator. Database tools often export tabs, and some legacy systems use a pipe (|). The converter inspects the first lines of your file and picks the delimiter that splits every line into the same number of fields.
Files saved by Excel as CSV UTF-8 begin with an invisible byte-order mark. Many converters leave it attached to the first header, producing a key like "\ufeffid" that breaks code which looks up id. DataSwitch Pro removes it, and files in Windows-1252 or UTF-16 are decoded automatically when uploaded.
Quotes and line breaks inside cells
The parser follows RFC 4180, the closest thing CSV has to a standard. A field wrapped in double quotes may contain commas, semicolons and even line breaks; a double quote inside such a field is written twice (""). For example "He said ""hi""" becomes the JSON string "He said \"hi\"". If a quote is never closed, the converter warns you instead of guessing.
Common problems and fixes
- Every row is one long string: the delimiter is wrong — choose it manually in Options.
- Strange characters such as é instead of é: the text was pasted from a non-UTF-8 source. Upload the file instead so its encoding is detected.
- Numbers came out as strings: they contain spaces, currency symbols or thousands separators (
1,200). Clean them in the spreadsheet first, or convert them in your code. - You started from an Excel file: use the Excel to JSON converter to skip the CSV step entirely.
Convert CSV to JSON in code
For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.
Python
import csv, json
with open("data.csv", newline="", encoding="utf-8-sig") as f:
rows = list(csv.DictReader(f)) # use delimiter=";" if needed
with open("data.json", "w", encoding="utf-8") as f:
json.dump(rows, f, indent=2, ensure_ascii=False)
Node.js
// npm install csv-parse
import { readFileSync, writeFileSync } from "node:fs";
import { parse } from "csv-parse/sync";
const rows = parse(readFileSync("data.csv"), {
columns: true, bom: true, skip_empty_lines: true,
});
writeFileSync("data.json", JSON.stringify(rows, null, 2));
Frequently asked questions
Is this CSV to JSON converter free?
Yes. There is no sign-up, no row limit imposed by a server and no watermark. The page is supported by ads.
Does it work with Excel files?
Yes — either save them as CSV, or use the dedicated Excel to JSON converter, which reads .xlsx files directly. Semicolon-separated files from European Excel are detected automatically.
How do I keep every value as a string?
Untick Detect numbers & booleans in Options. Every cell is then written as a JSON string exactly as it appears in the file.
What happens to empty cells?
By default they become empty strings (""). Tick Empty cells as null to get null instead. Short rows are padded so every object has the same keys.
Can I convert the JSON back to CSV?
Yes. Click the swap button between the format selectors and the current JSON output becomes the input of a JSON to CSV conversion.