Values That Turn Into Numbers When CSV Becomes JSON — the Lost Leading Zero
Open a CSV file and every cell just looks like text. It's one line of comma-separated text — nowhere in the file does it say "this column is a number," "this column is a string." JSON, by contrast, is a format that clearly distinguishes value types, so {"zip":"05028"} and {"zip":5028} are completely different data. So a CSV-to-JSON converter has to guess, looking at the string in a cell: "this looks like a number, make it a number; this looks like a string, leave it." If that guess is sloppy, values that start with a leading zero — ZIP codes, phone numbers, employee IDs — lose that zero entirely.
1. Why "007" is a dangerous value
To a person, "007" also just looks like a number, but if this value is a ZIP code or employee ID, the two leading zeros are essential information for keeping the digit count correct. Yet JavaScript's Number("007") returns 7. If the converter uses the simple rule "if it parses as a number, make it a number" — judging only by isNaN() or the Number() result — then "007" silently becomes the integer 7, and a value originally three digits is stored in JSON as a one-digit number. The phone number "010-1234-5678" is a problem of the same family. That value itself has hyphens mixed in so it doesn't parse as a whole number, but in a table where just the area code sits in its own "010" cell, there's the same risk of losing the leading zero. It's essentially the same kind of accident as a spreadsheet program auto-recognizing a ZIP-code column as number format and erasing the "0."
2. How the MODOO HUB converter actually decides
Checking the source of this site's CSV to JSON converter directly, the inferType() function that decides a value's type operates in this order. First, if the value is exactly "true" or "false", it becomes a boolean. Next, an empty string is left as-is. Finally, for the number check it uses the following regex instead of Number() or isNaN().
/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/The key point is that it allows only an integer part that is the single character "0" alone, or starts with 1-9 followed by digits. "007" has "07" after the "0" so it doesn't fit the "0 alone" condition, and it doesn't start with 1-9 either, so the entire regex fails to match. On match failure the function returns the original string.
Thanks to this rule, values with leading zeros like "007", "0502", "010-1234-5678" all fail the regex match and stay strings, while only conventional number notation like "0", "123", "3.14", "-7", "1e10" is converted to an actual number type. So unlike the common implementation of patching it with one line of Number(), this site's converter blocks the leading-zero-loss bug by regex design from the start.
| Input value | Conversion result | Why |
|---|---|---|
| 007 | "007" (kept as string) | Starts with 0 and has more digits after, so regex fails |
| 010-1234-5678 | "010-1234-5678" (kept as string) | Contains hyphens, so not number format to begin with |
| 05028 | "05028" (kept as string) | Multi-digit value starting with 0 |
| 0 | 0 (converted to number) | "0" alone is valid number notation |
| 123 | 123 (converted to number) | Normal number starting with 1-9 |
3. Why you should still check yourself
This site's converter blocks the leading-zero problem with a regex, but you shouldn't assume every CSV-JSON conversion tool works the same way. "0502" may already have become "502" during the export from Excel to CSV, and other online converters or a programming language's library may use different criteria. If you have a column where a leading zero carries meaning — ZIP code, phone number, employee ID, account number — the surest habit is to open the output JSON after conversion and visually confirm the value is kept as a double-quoted string.
4. Summary
- CSV has no types: every value is just text, so the converter has to guess whether it's a number.
- A plain Number() check is risky: "007" → 7 can silently drop the leading zero.
- This site's converter defends with a regex: only "0" alone or values starting with 1-9 become numbers; the rest stay strings.
- Eyeball important columns after conversion: check that ZIP code, phone number, and employee ID columns keep their quotes in the result JSON.
Frequently Asked Questions
Q. Does a CSV "007" value become the number 7 when converted to JSON?
A. Not with MODOO HUB's CSV to JSON converter. It restricts the number-recognition condition to the regex /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/, which allows only "0" alone or a number starting with 1-9. "007" starts with 0 and has more digits after, so it doesn't match, the regex fails, and the original string "007" is kept.
Q. Is there a risk of a phone number like 010-1234-5678 becoming a number?
A. No. A value containing hyphens never matches the number regex in the first place, so it stays a string from the start. Even a pure digit sequence like 01012345678 with no hyphens stays a string by the above rule if it has a leading zero, so no loss occurs.
Q. What values does this converter actually turn into numbers or booleans?
A. The strings "true"/"false" become booleans, and only values that are 0 or start with 1-9 followed by digits (optionally with decimal/exponent notation) become numbers. For example "123", "0", "3.14", "-7" become numbers, but "007", "010-1234", "1a2" — not pure number format or with an unnecessary leading zero — all stay strings.
Q. Do all CSV-JSON conversion tools behave this safely?
A. No. Some spreadsheet programs and simple converters judge numeric-ness with only JavaScript's Number() function or an isNaN() check, which converts "007" straight to Number("007")=7 and loses the leading zero. Before feeding data into a converter, it's safest to always check yourself that values with leading zeros are preserved in the result.