CSV type inference: why zip codes lose zeros

25 NOVEMBER 2026 · 8 MIN READ

Turning CSV into JSON means guessing whether <code>007</code> is a number, a code or a version. The guess is made by one small function, its rules are knowable, and every failure it produces is the same shape: text that looked like a number stops being text.

CSV is a quoting rule and nothing else. There are no types, no lengths, no encoding declaration and no way to say "this column is an identifier that happens to be written with digits". So a CSV-to-JSON converter has to infer, and inference is where the data changes. The conversion here runs the type guess on every cell; understanding its five rules turns a mystery into a checklist.

The rules, in order

  1. 01 true, TRUE, false, FALSE become booleans. Mixed case such as True stays the string it is.
  2. 02 Anything matching -? then digits with an optional fraction and an optional exponent, with surrounding spaces allowed, becomes a number — but only if the result stays below 2^53 in magnitude.
  3. 03 A full ISO 8601 timestamp with a time component becomes a date, which then serialises back in UTC.
  4. 04 An empty cell becomes null.
  5. 05 Everything else stays a string, including null written as text, which you cannot tell apart from a real null.
A file and what it turns into
zip,qty,longid,version,ts,phone,money
007,42,12345678901234567890,1.2.3,2026-11-24T09:30:00+02:00,555-1234,-1,234.50

-> [{"zip":7,"qty":42,"longid":"12345678901234567890","version":"1.2.3",
    "ts":"2026-11-24T07:30:00.000Z","phone":"555-1234","money":-1}]
The convert module turning a two-row CSV into JSON: 007 became 7, TRUE became the boolean true, True stayed a string, the 20-digit id stayed a string and the empty cell became null
The same rows run through the converter on this page

What each column teaches

CellResultReason
0077matches the number shape and is small; the zeros were never part of a number — the classic lost postal code, extension and version file
3.503.5a number has no memory of trailing precision; money should be an integer minor unit or a string
12345678901234567890unchanged textabove 2^53, so the converter refuses to make it a number and keeps the digits
1e31000scientific notation is in the pattern, so a code that starts with a digit and contains e can be rewritten
+7"+7"a leading plus is not in the pattern, so it survives by accident rather than by design
1.2.3"1.2.3"two dots do not parse; semver is safe for the wrong reason
0x10"0x10"hex is not JSON-shaped, so it stays text
-1,234.50-1the thousands separator is a field delimiter, so the value splits and the remainder is discarded — quote the cell or drop the separator
2026-11-24the same stringa date with no time does not match the timestamp pattern
2026-11-24T09:30:00+02:002026-11-24T07:30:00.000Zsame instant, different spelling: the offset is normalised to UTC and milliseconds are added

The part people blame the converter for

Two of the failures above are not really the converter’s choice. The 20-digit id survives only because it is large; shrink it to 15 digits and it becomes a number with full precision. And the timestamp is converted correctly — it is the spelling that changed, which matters as soon as you diff the JSON against another export or a schema that expects [+-]\d\d:\d\d in the pattern. If a column must round-trip exactly as written, it must stay text, and text is only guaranteed when the value cannot be mistaken for a number.

Going the other way is worse

Export writes values with the minimum quoting that RFC 4180 allows, so a JSON string "007" lands in the file as bare 007 — and Excel, Numbers and Google Sheets will apply their own, more aggressive inference to it on open. Two further export behaviours are worth knowing: nested objects become dotted column names (owner.email), and arrays are joined, so [1, 2] is written as "1,2" inside quotes. A CSV export of nested JSON is a flattened projection, not a lossless archive.

Spreadsheets and formulas

A cell that begins with =, +, - or @ is a formula to a spreadsheet. A value such as =1+1 survives a JSON round trip untouched, and then evaluates the moment someone opens the export — which is both a data-integrity bug and the standard CSV-injection vector for anything a human later opens. Prefix the cell with a single quote or force the column to text in the import wizard; treat any export that mixes user text with spreadsheet consumers as needing that guard.

Keeping identifiers intact

  1. 01 Decide before converting which columns are identifiers, because after inference you cannot tell 007 from 7.
  2. 02 Prefer JSON as the interchange format and CSV only as a human deliverable; the two conversions are not inverses of each other.
  3. 03 After importing, run schema inference over the rows: a zip column inferred as integer is the warning you wanted before the data hit a database.
  4. 04 For a column that must stay text, generate it as text at the source — most writers will quote it, but quoting is not preserved as a type hint.
  5. 05 Watch for ragged rows. A row with one field too many is reported as an error rather than truncated, which is the behaviour you want; a silent truncation of a money column is how -1,234.50 becomes -1 in an archive nobody questions.

NOTE A header is only a name. Nothing in a CSV file tells a reader that id is a string, that zip has leading zeros or that ts is local time — every tool that opens the file invents those facts independently, and they will not all invent the same ones.

TOOL MATRIX

Tools for this guide

Keyboard shortcuts
FORMATTING
Format input Ctrl/⌘ + Enter
Toggle auto-format Ctrl/⌘ + Shift + A
CLIPBOARD & FILES
Copy output Ctrl/⌘ + K
Open JSON file Ctrl/⌘ + O
Download output Ctrl/⌘ + S
Save snippet Ctrl/⌘ + Shift + N
MODULES
Open find & replace Ctrl/⌘ + Shift + F
Lock / unlock output Ctrl/⌘ + Shift + L
Show this dialog Ctrl/⌘ + /
Local history
Save snippet
Erase local data

Nothing is stored in this browser yet.

Removes the saved draft, history, snippets and formatting options for this site. Documents you typed stay in the editor until the page reloads.