How to Convert a CSV File to JSON
3 methods — browser tool, Python, and Node.js
Converting CSV to JSON is a common step when feeding spreadsheet data into a web app, API, or database. The output is a JSON array of objects, where each row becomes an object and each column header becomes a key.
Method 1: Using Tabular (no code required)
The fastest option — upload your CSV and download JSON in seconds.
- 1Go to the CSV to JSON tool on Tabular.
- 2Upload your CSV or XLSX file.
- 3Click Run — Tabular converts every row into a JSON object using your column headers as keys.
- 4Download the .json file.
Column headers with spaces become JSON keys with spaces (e.g. 'First Name' → "First Name"). Use Tabular's Rename Columns tool first if you want clean key names like firstName.
Method 2: Using Python (pandas)
Good for batch processing or when you need to transform the data during conversion.
- 1Install pandas: pip install pandas
- 2Run the script below.
python
import pandas as pd
df = pd.read_csv("input.csv")
# Convert to JSON array of objects
json_output = df.to_json(orient="records", indent=2)
with open("output.json", "w") as f:
f.write(json_output)orient='records' produces [{col: val, ...}, ...] format. Use orient='index' for an object keyed by row number instead.
Method 3: Using Node.js
Useful if you're already in a JavaScript/TypeScript environment.
- 1Install the csv-parse library: npm install csv-parse
- 2Run the script below.
javascript
const { parse } = require("csv-parse/sync");
const fs = require("fs");
const csv = fs.readFileSync("input.csv", "utf8");
const records = parse(csv, { columns: true, skip_empty_lines: true });
fs.writeFileSync("output.json", JSON.stringify(records, null, 2));
console.log(`Converted ${records.length} rows to JSON`);Frequently asked questions
What does the JSON output look like?
The output is a JSON array of objects. Each CSV row becomes one object, and each column header becomes a key. For example, a row with columns 'Name' and 'Email' produces: [{"Name": "Alice", "Email": "alice@example.com"}, ...]
Are numbers and booleans preserved as their correct types?
It depends on the tool. Tabular converts all values to strings to preserve data exactly as it appears in the CSV. Python's pandas will infer types — numeric columns become numbers automatically. If you need specific types, use pandas with dtype options or post-process the JSON.
How do I convert a large CSV to JSON without running out of memory?
For very large files, use Python with chunked reading: pd.read_csv('input.csv', chunksize=10000). Process each chunk and append to your output file rather than loading the whole dataset at once.
Can I convert JSON back to CSV?
Yes. Use Tabular's JSON to CSV tool — upload your JSON array and download a CSV. In Python, use pd.read_json('input.json').to_csv('output.csv', index=False).
Ready to try the fastest method?
Upload a CSV file and instantly convert it to a clean JSON array. Free, no signup required.
CSV → JSON — free
Papiral
Tabular