TOOLFRED WORKED EXAMPLE
Keep leading zeros and large IDs when converting CSV to JSON
A three-record experiment shows why identifiers and exact decimal strings should not be guessed into numbers.
THE SHORT ANSWER
How can I keep leading zeros in CSV-to-JSON conversion?
Keep identifier columns as strings and avoid automatic numeric conversion. Toolfred’s CSV-to-JSON workflow keeps every cell as text: 001 stays "001", and 9007199254740993 retains all its digits. The receiving application must also preserve those strings.
| CSV value | Toolfred JSON value | What numeric guessing can lose |
|---|---|---|
| 001 | "001" | Leading zeros |
| 9007199254740993 | "9007199254740993" | Exact integer digits in JavaScript Number |
| 12.00 | "12.00" | Original decimal formatting |
| Empty cell | "" | Difference from zero or null |
Try a file designed to expose conversion mistakes
Download the synthetic practice CSV and open the CSV to JSON converter. Convert CSV to JSON. The output should match the expected JSON. Both files contain invented data.
ID,Label,PostalCode,Amount
001,First,00501,12.00
1,Second,02108,0
9007199254740993,Third,,
Compare text values with numeric conversions
The two IDs 001 and 1 are distinct strings. Converting both to numbers produces 1 and loses that distinction. Postal code 00501 is also text: zero is part of its written identifier, not a quantity to remove.
The final ID is 9007199254740993. It exceeds JavaScript's largest safe integer, 9007199254740991. Converting it to a JavaScript Number produces 9007199254740992. Keeping it as a JSON string preserves every digit. This is a binary64 integer-representation example, not a rule that every programming language loses the same value.
Amounts need an explicit schema
Toolfred exports 12.00 as the string "12.00" in this workflow. A JSON number 12.00 does not retain that textual decimal formatting after ordinary parsing and serialization. An empty field becomes an empty string, not an inferred zero or null. Convert to a numeric or nullable field only when your destination's documented schema calls for it. Do not treat text preservation as automatic import compatibility.
Quoting CSV does not assign types
CSV quotes enclose fields containing commas, quotes or newlines. They do not provide a universal text-column instruction to a spreadsheet. A spreadsheet may still auto-convert a quoted identifier; import that column explicitly as text. Review exported values before loading them into another system.
Check the result rather than its appearance
In the JSON output, verify that 001 and 1 remain quoted and distinct, the large ID still ends in 993, and Amount stays "12.00". All values in this converter are strings. The example is independently checked against the actual parser and converter during development.
Sources: RFC 4180 CSV conventions; RFC 8259 number interoperability; JavaScript safe integers.
Questions or corrections
Report a reproducible issue to contact@toolfred.com using an invented example. Avoid sensitive files. How we check tools and maintain examples →