belun.app Blog
RU

CSV to JSON: Delimiters, Quotes, and the Leading-Zero Trap

How header rows become keys, why auto-detection beats guessing the delimiter, and the type-coercion gotcha that eats your ZIP codes.

Laptop screen showing a spreadsheet of rows and columns being converted into a JSON array

Someone exports a sheet, hands you a .csv, and now you need it as JSON for an API call, a config file, or a quick script. The shape is right there — rows and columns map almost perfectly onto an array of objects. Almost. The three places it goes wrong are the delimiter, the quoting, and what happens to your numbers.

Header rows become keys

The clean case is a file with a header row. The first line names the columns, every line after it is a record:

name,role,city
Ada,Engineer,London
Linus,Maintainer,Portland

That turns into two objects, each with name, role, and city keys. Easy. Turn the header option off and you get arrays of values instead — useful when the file is a raw matrix with no column names, or when the first row is real data you don’t want stolen for keys. Pick whichever matches what you’re feeding it.

The delimiter is rarely a comma

CSV stands for comma-separated values, and then half the files you meet aren’t. Export from a German or French copy of Excel and the separator is a semicolon, because in those locales the comma is already the decimal point. Pull a table out of a database and it’s often tab-separated. A pipe shows up in log dumps.

Guessing wrong is the single most common reason a “CSV” lands as one giant column. So instead of assuming a comma, the converter reads the first line and counts how often each candidate — comma, semicolon, tab, pipe — appears, then goes with the winner. It’s a small heuristic and it’s right almost every time. When it isn’t, the dropdown lets you force the exact one.

Quotes are doing more work than you think

A field with a comma in it, like a full address or Smith, Jane, would shred the row if written raw. The CSV rule, spelled out in RFC 4180, is to wrap that field in double quotes. A quote inside the value gets doubled — "She said ""hi""". The parser here follows that to the letter, so quoted fields can hold commas, line breaks, and escaped quotes, and the row still splits in the right places. Naive split-on-comma converters fall apart on exactly this, which is why a contact export with one address in it can produce a JSON file where every record after row 40 is shifted one column to the left.

The leading-zero trap

Here’s the one that quietly corrupts data. You want "42" to become the number 42, not the string "42" — that’s the whole point of typing values. But blanket coercion is dangerous. A US ZIP code like 02134 is text, not the number 2134. A product code 007, a phone number, a German postal code starting with zero — all of them lose their leading digits the moment you treat them as numbers.

So the type detection here is deliberately narrow. It converts plain integers and decimals and the words true and false, but anything with a leading zero stays a string. If you’d rather keep every value as text and decide types yourself downstream, switch the “Typed values” toggle off and nothing gets coerced.

Run it

Paste your CSV or drop in a .csv file, check that the row and column counts look right, and copy the JSON straight into your editor. It all runs in your browser — nothing is uploaded — so even a customer list with real names stays on your machine. Open the CSV to JSON Converter and try it on whatever’s sitting in your downloads folder.

Try the tool

CSV to JSON Converter →