How CSV rows become JSON
With a header row, each column name becomes a property and each data row becomes one object:
id,name,active,zip
1,"Hopper, Grace",true,02134
[
{ "id": 1, "name": "Hopper, Grace", "active": true, "zip": "02134" }
]Note what happened to each value. 1 became a number and true a boolean, the comma inside the quoted name did not split the field, and 02134 stayed a string, because a number cannot have a leading zero and turning it into 2134 would corrupt the ZIP code.
Choosing the JSON shape
| Output | Looks like | Best for |
|---|---|---|
| Array of objects | [{"id":1,"name":"Ada"}] | APIs, front-end apps, most code. The default. |
| Array of arrays | [["id","name"],[1,"Ada"]] | Charts and tables that take rows, smaller files |
| Keyed by first column | {"1":{"name":"Ada"}} | Lookups by ID, translation files, config maps |
| JSON Lines | One object per line, no wrapping array | Large datasets, BigQuery loads, logs, AI fine-tuning files |
Getting the data types right
- Numbers are detected only when the value is a plain number:
42,-3.5,1e6. Values with leading zeros, thousands separators (1,200) or currency symbols stay strings. - Very large integers, above 9,007,199,254,740,991, stay strings. JavaScript and most JSON parsers can't store them exactly, so an order ID like
12345678901234567890would otherwise change. - Trailing zeros disappear when a value becomes a number:
1.50is1.5. If prices must keep their format, turn type detection off. - Dates stay strings. JSON has no date type, and ISO 8601 strings like
2026-11-30are what most APIs expect. - Empty cells can become
"",null, or be left out of the object, depending on what the code reading the JSON expects.
CSV quirks this converter handles
CSV looks simple, but the rules in RFC 4180 trip up hand-written parsers that just split on commas:
- A field containing the delimiter, a quote or a line break is wrapped in double quotes:
"Hopper, Grace". - A quote inside a quoted field is written twice:
"Grace ""Amazing"" Hopper". - A quoted field can span several lines, so one record is not always one line.
- Files saved by Excel may start with an invisible byte-order mark, which would otherwise end up in the first column name.
- Excel in much of Europe saves with semicolons, because the comma is the decimal separator there.
If a quoted field is never closed, the converter says on which line it started, which is usually where the export went wrong.
Converting CSV to JSON in code
# Python (standard library)
import csv, json
with open("data.csv", newline="", encoding="utf-8-sig") as f:
rows = list(csv.DictReader(f))
json.dump(rows, open("data.json", "w"), indent=2)
# Note: DictReader keeps every value as a string.
# Command line
csvjson data.csv > data.json # csvkit
mlr --icsv --ojson cat data.csv > data.json # MillerThe utf-8-sig encoding in the Python example strips the byte-order mark Excel adds. In JavaScript, use a tested parser such as Papa Parse or csv-parse rather than split(","), which breaks on the first quoted comma.
Going the other way? The JSON to CSV Converter flattens nested JSON into columns and prepares the file for Excel.
Frequently asked questions
How do I convert a CSV file to JSON?
Paste the CSV or open the file, and the JSON appears as you type. By default the first row becomes the property names and each following row becomes one object in an array. Copy the result or download it as a .json file.
Why does my ZIP code or phone number lose its leading zero?
Some converters turn every numeric-looking value into a number, and 02134 becomes 2134. This converter only treats a value as a number when it has no leading zero, so ZIP codes, phone numbers and IDs such as 007 stay strings. You can also switch type detection off to keep every value as a string.
My CSV uses semicolons. Will it still work?
Yes. The delimiter is detected from the first lines, so comma, semicolon, tab and pipe files all work. Semicolons are common in files exported by Excel in countries that use a comma as the decimal separator.
Can I create nested JSON from a CSV?
Yes. Name the columns with dots, such as address.city and address.zip, and turn on the nesting option. Those columns become an address object with city and zip properties.
What is JSON Lines and when should I use it?
JSON Lines puts one JSON object on each line instead of wrapping everything in an array. It suits large datasets and logs because tools can read it one line at a time. BigQuery, many data pipelines and fine-tuning datasets for AI models use it.
Is my CSV uploaded to a server?
No. Parsing and conversion run in your browser, so the data never leaves your device. That makes it safe for customer lists, exports from internal systems and other private data.
Related Tools
- JSON to CSV Converter — Convert JSON or JSON Lines to CSV with nested-object flattening, array handling, an Excel-friendly UTF-8 BOM and protection against formula injection.
- Cron Expression Generator — Build and read cron expressions in plain English, see the next 10 run times, and convert between crontab, Spring, Quartz and AWS EventBridge formats.
- CSS Minifier & Beautifier — Minify CSS with only rendering-safe changes, keeping licence comments, strings and calc() intact, or beautify minified CSS into readable, indented code.
- URL Encoder & Decoder — Percent-encode or decode URLs and query strings with component, full-URL, RFC 3986 or form (+) rules.
- Base64 Decode & Encode — Decode Base64 to text, images or files and encode text or files to Base64 and data URIs.
- Meta Tag Checker — Check a page's title, meta description, robots directives, canonical, viewport and hreflang tags, with a Google result preview and a fix for each issue.