How to Convert CSV to JSON: 3 Easy Methods
CSV files are easy to export but awkward for APIs and web apps, which expect JSON. The conversion is simple in principle: the header row becomes the keys, and every other row becomes an object. Here are three ways to do it.
Method 1: Use a browser-based converter
The fastest option for one-off jobs. Paste your data into our CSV to JSON converter, click To JSON and copy the result. Because it runs in your browser, nothing is uploaded, which matters for customer or financial data.
Method 2: Python
Best for repeatable scripts. The standard library handles quoting and commas correctly:
import csv, json
with open("data.csv", newline="", encoding="utf-8") as f:
rows = list(csv.DictReader(f))
with open("data.json", "w", encoding="utf-8") as out:
json.dump(rows, out, indent=2, ensure_ascii=False)
Method 3: JavaScript
For simple files with no quoted commas, a few lines are enough:
const [head, ...lines] = csvText.trim().split("\n");
const keys = head.split(",").map(k => k.trim());
const data = lines.map(line => {
const vals = line.split(",").map(v => v.trim());
return Object.fromEntries(keys.map((k, i) => [k, vals[i]]));
});
If your values can contain commas or line breaks, use a CSV parsing library instead of split.
Common mistakes
- Missing header row: without it, keys become the first data row.
- Inconsistent columns: rows with extra or missing values produce misaligned objects.
- Everything is a string: CSV has no types, so convert numbers and booleans if your app needs them.
- Wrong encoding: save as UTF-8 to keep accented characters.
Frequently asked questions
Can I convert an Excel file to JSON?
Save the sheet as CSV first: in Excel choose File, Save As, then "CSV UTF-8". Then paste or upload that file into the CSV to JSON converter. Each sheet needs its own CSV file.
Why are my numbers turned into text in the JSON?
CSV has no types, so every value is just text. A good converter guesses that values like 42 or 3.5 are numbers. Watch out for codes with leading zeros, such as PIN codes or phone numbers, which should stay as text so the zeros are not lost.
How do I handle commas inside a value?
Values that contain commas must be wrapped in double quotes in the CSV, for example "Mumbai, India". Spreadsheet programs do this automatically when they export. Problems usually come from CSV files typed by hand.
Is there a size limit for CSV to JSON?
The converter runs in your browser, so the limit is your device memory. Files of several megabytes and tens of thousands of rows are fine. For very large files, a short Python script is the better tool.
Is my data uploaded when I convert?
No. The conversion happens on your own device, which matters for customer lists, sales data and anything personal.
Convert your file in seconds with the free CSV to JSON, SQL and Markdown converter.