How to Convert CSV to JSON: Output Shapes, Types & Delimiters Explained
Convert CSV to JSON the right way — choose the output shape, infer types correctly, handle quoted fields and odd delimiters, and do it online, in Python, or with Node.
CSV comes out of spreadsheets, databases, and analytics exports; JSON is what APIs and JavaScript want. Converting one to the other is a daily task, and while a naive split(',') gets you 80% of the way, the last 20% — quoted fields, types, and the shape of the result — is where it matters. This guide covers how to convert CSV to JSON cleanly: online in one click, in Python, and in Node.
The quickest way: convert CSV to JSON online
For a one-off conversion, use a browser tool. Copy your CSV, paste it into the CSV to JSON converter, and press Convert to JSON. The first row becomes your keys, each following row becomes an object, and you can copy or download the result immediately.
Pick a converter that runs client-side (ours does) so your data is never uploaded — important for exports containing customer or financial data. It also means there is no file-size cap: server-based converters often reject anything large, while a local tool is limited only by your machine’s memory.
Use it when: you want a fast, private conversion on any device with no install.
Choose the right output shape
This is the decision most tutorials skip. The same CSV can become three different, equally valid JSON structures — pick the one your code consumes.
Array of objects (the default)
One object per row, keyed by the header. This is what REST APIs and most JavaScript expect:
[
{ "id": 1, "name": "Ada", "city": "London" },
{ "id": 2, "name": "Alan", "city": "Manchester" }
]
2D array (array of arrays)
The raw grid, header included. Compact, and ideal for spreadsheets, charts, and table components:
[
["id", "name", "city"],
[1, "Ada", "London"],
[2, "Alan", "Manchester"]
]
Keyed by column (column-oriented)
Each key maps to an array of that column’s values. This maps directly onto a pandas DataFrame or a columnar store:
{
"id": [1, 2],
"name": ["Ada", "Alan"],
"city": ["London", "Manchester"]
}
Our converter offers all three from a single dropdown, so you don’t have to reshape the output yourself.
Get the types right
A CSV cell is always text, but JSON has real types. Good conversion infers them:
42→ number,3.14→ numbertrue/false→ booleannull→ null- everything else → string
The classic trap is over-eager inference. An ID like 007, a ZIP code like 02134, or a phone number +15551234 should stay a string — turning them into numbers silently drops the leading zero or the plus sign. A careful converter (ours included) only treats a value as a number when it is a clean numeric literal without a leading zero. When in doubt, switch type inference off for lossless, all-string output.
Handle quoted fields and weird delimiters
Real CSV is messier than it looks. Two things break naive splitters:
Quoted fields. A value may contain the delimiter, line breaks, or quotes, so it gets wrapped in double quotes per RFC 4180:
name,note
"Smith, John","Said ""hello"" twice
on two lines"
That is two columns and one row — Smith, John and a two-line note — not a broken file. A proper parser keeps it intact; split(',') shreds it.
The delimiter may not be a comma. European exports often use semicolons (because the comma is a decimal separator), and TSV files use tabs. A good tool auto-detects the delimiter and lets you override it. Converting TSV to JSON is just CSV-to-JSON with a tab delimiter.
Convert CSV to JSON in Python
For pipelines, Python’s standard library handles it without dependencies:
import csv, json
with open("data.csv", newline="") as f:
rows = list(csv.DictReader(f)) # list of dicts, header-keyed
with open("data.json", "w") as f:
json.dump(rows, f, indent=2)
DictReader gives you the array-of-objects shape directly. Note that every value is a string — add your own type coercion if you need numbers. For heavier work, pandas.read_csv("data.csv").to_json(orient="records") infers types and supports other orientations (orient="columns" for column-keyed, orient="values" for a 2D array).
Convert CSV to JSON in Node.js
In Node, a small parser keeps quoted fields safe (don’t hand-roll split):
import { parse } from "csv-parse/sync";
import { readFileSync, writeFileSync } from "node:fs";
const rows = parse(readFileSync("data.csv"), {
columns: true, // first row as keys → array of objects
cast: true, // infer numbers/booleans
skip_empty_lines: true,
});
writeFileSync("data.json", JSON.stringify(rows, null, 2));
Which method should you use?
For a quick, private conversion — especially when you want to choose the output shape or you have a large or messy file — use the online CSV to JSON converter: paste, pick your shape and delimiter, and download. Use Python or Node when the conversion lives inside a script or pipeline. Either way, the two decisions that matter are the same: which JSON shape you need, and how aggressively to infer types.
Going the other direction? See how to convert JSON to CSV. New to the format? Read what is JSON, and validate tricky output with the JSON validator.
Ready to merge your JSON?
Combine files or snippets in your browser — free and private.
Open the merge toolKeep reading