What the conversion produces
A CSV like this:
name,email,age,active
John Doe,john@example.com,30,true
Jane Smith,jane@example.com,25,falseBecomes a JSON array of objects, one per row, using the header row as property names:
[
{
"name": "John Doe",
"email": "john@example.com",
"age": "30",
"active": "true"
},
{
"name": "Jane Smith",
"email": "jane@example.com",
"age": "25",
"active": "false"
}
]Notice: all values are strings by default. CSV has no type system — everything is text. If you need age as a number and activeas a boolean, you'll need to handle type coercion after conversion.
Convert any CSV file using the free CSV to JSON converter — paste CSV or upload a file, get formatted JSON instantly.
Handling the common problems
Commas inside field values
RFC 4180 (the CSV standard) handles commas inside field values by wrapping the field in double quotes:
name,address,city
John,"123 Main St, Apt 4B",SpringfieldThe addressfield contains a comma but is correctly parsed as one value because it's quoted. Any proper CSV parser handles this — but if you're writing a simple split-on-comma parser yourself, you'll miss this and get the wrong result. Use the converter or a proper library.
Quotes inside quoted fields
name,bio
John,"He said ""hello"" to everyone"Double-quote characters inside a quoted field are escaped by doubling them (""). The resulting JSON:
{"name": "John", "bio": "He said "hello" to everyone"}Different delimiters (TSV, semicolons)
Not all "CSV" files use commas. European locales often export with semicolons (;) because commas are used as decimal separators. Tab-separated values (TSV) use tabs.
The converter lets you specify the delimiter — choose comma, semicolon, tab, or pipe (|) depending on your source file.
Type conversion after parsing
Since CSV values are all strings, you'll often need to convert types in code. In JavaScript:
const raw = [
{ name: "John", age: "30", active: "true" }
];
const typed = raw.map(row => ({
...row,
age: Number(row.age),
active: row.active === 'true'
}));
// Result: { name: "John", age: 30, active: true }For large datasets, consider using a library like Papa Parse (browser) or fast-csv (Node.js) which supports type inference options.
Converting in code (no tool needed)
If you need to convert CSV to JSON programmatically:
JavaScript (browser/Node.js, simple case):
function csvToJson(csv) {
const lines = csv.trim().split('\n');
const headers = lines[0].split(',');
return lines.slice(1).map(line => {
const values = line.split(',');
return headers.reduce((obj, header, i) => {
obj[header.trim()] = values[i]?.trim() ?? '';
return obj;
}, {});
});
}Note: this simple approach doesn't handle quoted fields with commas inside them. For production use, use Papa Parse or a proper CSV library.
Python:
import csv, json
with open('data.csv', newline='') as f:
reader = csv.DictReader(f)
data = list(reader)
print(json.dumps(data, indent=2))Common use cases
- Google Sheets → API payload: Export as CSV → convert to JSON → POST to a REST API that expects JSON
- Excel data → database seed: Convert CSV export to JSON for seeding a database via a script
- Product catalog import: Many e-commerce platforms accept JSON imports — convert your spreadsheet product data
- Data analysis prototype: Convert CSV data to JSON to use with JavaScript charting libraries (Chart.js, D3.js) that expect JSON arrays
Related tools
- Free CSV to JSON Converter — convert CSV files or paste CSV text to JSON instantly
- Free JSON Formatter — format and validate the resulting JSON
Written by Achraf A., founder of TheFreeAITools.