How to convert CSV to JSON without losing data

Learn the rules of CSV, how to export a spreadsheet correctly, and how to keep ZIP codes, dates and prices from getting mangled in your JSON.

Your product list lives in a spreadsheet, but the new system, the API or the app only takes JSON. Copying row by row is out of the question, and a quick script tends to trip over the first name with a comma in it or the first ZIP code that starts with zero.

Converting CSV to JSON sounds simple — each row becomes an object, each column a key — but CSV has a few little-known rules, and that's exactly where data gets lost. To try it with your own data, open the CSV to JSON converter.

How does a CSV row become a JSON object?

The first line of the CSV, the header, supplies the key names. Every following row becomes an object with those keys, in column order, and the whole file becomes an array of objects. Without a header row, keys have to be invented — the converter uses column1, column2 and so on.

A CSV with a header row and a quoted field converted into a JSON objectCSV (,)name,city,zip"Lee, Ava",Boston,02134quotes protect the comma in the nameJSON{ "name": "Lee, Ava","city": "Boston","zip": "02134" }Kept as text"02134" keeps the ZIP's leading zeroIf it became a number2134 — no longer a valid ZIP code
The header names the keys; quotes keep the delimiter inside a field; codes with leading zeros must stay text.

The CSV rules that break conversions

There's no single CSV standard, but the most widely accepted reference is RFC 4180. The rules that trip up hand-rolled conversions most often:

A parser that follows RFC 4180 — like the converter's — handles every one of these cases automatically.

How to export your spreadsheet as CSV the right way

Good conversions start at export time. A properly generated CSV prevents a good share of the problems:

AppHow to exportDelimiter produced
ExcelFile > Save As > CSV UTF-8 (Comma delimited)Your system's list separator — a comma on US/UK settings, a semicolon in much of Europe
Google SheetsFile > Download > Comma-separated values (.csv)Always a comma, always UTF-8
Numbers (Mac)File > Export To > CSV, with Unicode (UTF-8) encodingComma on US settings

Always pick the UTF-8 option so special characters survive, and export one sheet at a time — CSV only stores the active sheet. In the converter, leave the delimiter on “Detect automatically”: it inspects the first lines and chooses between comma, semicolon, tab and pipe. If you're wondering where Excel's semicolons and garbled accents come from, how to convert JSON to CSV explains both in detail.

Which CSV values should not become numbers?

Codes that only look numeric — ZIP codes, phone numbers, account numbers, SKUs — should stay text in your JSON. Nobody does math with them, and converting them wipes out leading zeros or digits. Ages, quantities and plain numeric prices, on the other hand, can become numbers so the target system can calculate with them.

In CSV everything is text, so the call is yours. The converter's automatic option applies to every column at once and turns anything that looks like a number into a number. There are only two exceptions: integers that start with zero, like 02134, and integers too long for JavaScript to represent exactly stay text. A ZIP code like 90210, an account number like 40012345 or a phone number typed as 5550104477 becomes a number.

If your sheet has ZIP codes, account numbers, SKUs or phone numbers stored as plain digits, leave automatic conversion off and convert only the truly numeric columns in the target system. The cases worth knowing:

Before you send the JSON: a quick checklist

The converter handles the mechanics, but only you know the system that will receive the data. Before importing the result, check:

  1. Do the counts match? The number of records in the JSON should equal the spreadsheet's row count, minus the header. A gap usually means an unclosed quote swallowed some lines.
  2. Were the flagged rows fixed at the source? Correct the spreadsheet and export again; hand-patching the JSON means the error comes back on the next export.
  3. Are the key names what the API expects? Rename columns in the spreadsheet (E-mail to email, for instance) instead of fixing object after object.
  4. Are required fields filled in? An empty cell becomes "" or null, depending on the option you pick — and an API may accept one and reject the other. Check the target's documentation.

Convert your spreadsheet now

The CSV to JSON converter detects the delimiter, respects quotes and embedded line breaks, strips the BOM, de-duplicates column names, flags inconsistent rows and lets you choose how to handle empty cells and types. Before sending the result to an API, it's worth checking that it has the expected shape — see how to validate JSON.

Frequently asked questions

How do I convert only some of the columns?

The converter turns every column in the file into a key. To get JSON with only some of them, copy the columns you need into a new sheet, or delete the others in a copy of the workbook, and export that sheet as CSV. Columns that are merely hidden still end up in the exported file.

Why does my first JSON key start with a strange character?

That's the BOM, an invisible marker Excel puts at the start of UTF-8 CSV files. Naive converters fold it into the first column name, producing a key like \ufeffname. The Util Hub converter strips the BOM automatically; in your own scripts, strip the U+FEFF character from the start (in Python, opening the file with the utf-8-sig encoding does it).

How do I get nested JSON objects from a CSV?

CSV is a flat table, so each row becomes a single-level object. If your system expects, say, an address object inside each customer, you'll need to reshape the result afterwards, in code or by hand. Naming columns like address.city documents the intent, but the key is still one plain string.

Why do accented characters show up as � after importing?

The file was saved in a legacy encoding, such as Windows-1252 (ANSI), rather than UTF-8. Export it again with your spreadsheet's CSV UTF-8 option, or open it in a text editor or LibreOffice and save it as UTF-8. Then import the file into the converter again.

References