Developer FIELD NOTES · 3 MIN READ
From CSV Rows to JSON Objects: How Conversion Works
How CSV becomes JSON: the header row as keys, the RFC 4180 quoting rules that come first, which values turn into numbers, and where conversions quietly bite.
CSV and JSON hold the same data with opposite instincts. CSV is one flat grid: values separated by commas, rows separated by newlines, and no memory of types. JSON is a tree of labeled values. Converting the first into the second is mostly about deciding where the labels come from and what each value becomes.
Two shapes for the same data
CSV is a rectangle: every row has the same columns, position carries meaning, and the first row usually names them. JSON prefers an array of objects — one object per row, header names as keys. Convert name,qty,price,note followed by "Widget, large",3,9.99,true and you get [{ "name": "Widget, large", "qty": 3, "price": 9.99, "note": true }]. The header row became the object keys and each data row became one object. That shape is why JSON is friendlier to code: you address row.name instead of counting columns.
Quoting rules come first
Before any JSON exists, the CSV must be read correctly, and the rules are RFC 4180's. A field containing a comma, quote, or line break is wrapped in double quotes, so "Widget, large" survives its comma intact. A quote inside a quoted field is doubled, so "" means one literal quote mark. Carriage returns paired with line feeds (\r\n) count as a single row break, so Windows-exported files parse identically to Unix ones. A converter that just splits on commas produces silently wrong data — the quoted comma is the classic case. How CSV Files Work walks through the full quoting grammar.
What becomes a number — and what stays text
CSV has no types; JSON does, so conversion must decide. The rule here: anything that parses as a number becomes a JSON number (3 and 9.99), the exact words true, false, and null become their JSON equivalents, and everything else stays a string — "not-a-number" arrives as "not-a-number". Empty cells become empty strings rather than null, preserving the difference between "blank on purpose" and "absent". This is also where conversions quietly bite: 007 becomes the number 7, and a quoted "1,234" stays a string because of the comma inside. Look at one converted row before trusting the whole file.
No header row? Columns get names anyway
Turn the header option off and the converter names the columns itself — col1, col2, and so on — treating every row, including the first, as data. That is the right mode for files that genuinely have no header, and a quick way to inspect the shape of unfamiliar data without inventing names for it.
Where conversion goes wrong
Ragged rows — fewer cells than headers — fill with empty strings rather than failing, and extra cells are ignored; both are worth checking when the source file was hand-edited. Numbers with currency symbols or thousands separators stay strings, which is usually correct but surprises people expecting decimals. And the road runs both ways with an asymmetry: CSV to JSON is lossless about structure but decisive about types, while the reverse direction must flatten nesting and pick a quoting dialect. Validate the JSON side with a validator before feeding it to an API; JSON Explained covers why the object shape is what most tools expect.
Try it yourself
Paste a few rows into the CSV to JSON Converter — include one quoted field with a comma inside and watch it survive as a single value. Toggle the header option to see col1-style keys appear, then send the output through the JSON Validator to confirm it parses cleanly. To go the other way, the JSON to CSV Converter flattens objects back into rows.