DEV Community

JSON2CSV
JSON2CSV

Posted on

Why Excel Breaks Your JSON-to-CSV Conversions (and How to Stop It)

I have lost count of how many times someone has said "the converter is broken, half my IDs are wrong" when the CSV was actually fine. The file was correct. Excel changed it when it opened it.

After running into this enough times, I built a browser-based converter that avoids the traps below. This post is about the traps themselves, because you will hit them whatever tool you use.

1. Excel keeps only 15 digits

Excel stores numbers as 64-bit floating point, so it shows 15 significant digits and replaces the rest with zeros. A 19-digit order ID like 1234567890123456789 opens as 1234567890123450000. The CSV still holds the right value, but if you save from Excel you overwrite it.

What to do: treat IDs as text, never as numbers. In CSV you cannot mark a column as text, so either import through Excel's Data > From Text/CSV and set the column type to Text, or export to .xlsx where the cell type is stored.

JSON has a similar problem one step earlier. JSON.parse in JavaScript also uses 64-bit floats, so an integer above 9007199254740991 is rounded before your code ever sees it. If your IDs are that large, ask the API to send them as strings, or use a parser that keeps the original digits.

2. Leading zeros disappear

A zip code like 02134 becomes 2134. Phone numbers lose their leading zero too. Same cause: Excel decides the column is numeric and drops the zero. Same fix: import as text.

3. Accents turn into garbage

If Müller appears as Müller, the CSV is UTF-8 but Excel opened it as a legacy Windows encoding. Writing the file with a UTF-8 byte order mark (BOM) fixes it, because Excel then detects the encoding. In Python that is encoding="utf-8-sig".

4. Everything is in one column

In many European locales, Excel expects a semicolon as the CSV separator because the comma is the decimal mark. A comma-separated file then lands in column A. Either use a semicolon delimiter for those users or import with an explicit delimiter.

5. Nested JSON has no single right answer

CSV is flat and JSON is not. When a record contains an object, the usual answer is to flatten it into columns like address.city. When it contains a list, you have to choose:

  • One row per list item, repeating the parent values. Good for analysis, but row counts grow.
  • The list in one cell, joined with a separator. Good for display, harder to filter.
  • Numbered columns such as tags.0, tags.1. Works only if lists are short.

None of these is wrong. The mistake is not choosing on purpose.

6. Not every JSON file is JSON

Log exports are often JSON Lines (one object per line, no outer brackets). A normal parser rejects the whole file. Read it line by line, and report the bad lines instead of stopping at the first one.

The tool

I put all of this into a converter that runs entirely in the browser, so your data is never uploaded: JSON2CSV.online. It flattens nested data, keeps long IDs and leading zeros as text, reads JSONL, and writes Excel-friendly CSV or .xlsx.

If you prefer code, these guides have the details and snippets:

It is a small project and I am still finding rough edges. If you have a file it gets wrong, tell me in the comments and I will look at it.

Top comments (1)

Collapse
 
jisung1122 profile image
Jiseong Yun | Yunju Company •

These Excel traps show up constantly in supplier files, not just in JSON exports. When I open a 1688 or Taobao price list saved as CSV, Excel drops leading zeros on SKUs, and it treats pack quantities as numbers, which is fine until a code like 0012 and a quantity live in the same sheet and one of them gets coerced. The encoding issue is different with Chinese files: a sheet that looks fine in a text editor often comes out as mojibake in Excel because the file is GBK or GB2312, not UTF-8. A UTF-8 BOM doesn't help in that case. I reopen it through Data > From Text/CSV, set the encoding explicitly, and force the SKU column to Text before I touch anything else. If I need a safe copy, I work in Google Sheets or a text editor first, then bring only the cleaned columns into Excel.