⇄LocalShift. Runs on your device
THE LOCALSHIFT FIELD GUIDE

Preserve leading zeros when converting CSV to JSON

Keep identifier fields as strings from the source export onward. LocalShift's CSV to JSON converter preserves CSV cells as strings, so 00123 becomes "00123" rather than the number 123.

Identifiers are not quantities

A postal code, customer ID or product code can consist entirely of digits without being a number you should calculate with. A leading zero can be meaningful. Date-like values may also need their original spelling rather than an interpreted date.

Start with the original CSV and open it in a text editor if necessary. If a spreadsheet has already saved 00123 as 123, a converter has no reliable way to infer the missing digits.

Try a short ID and a long ID

Paste this input into CSV to JSON. Keep the header enabled and select the comma separator. The output keeps both identifiers quoted, including an ID longer than the safe integer precision of common JavaScript numbers.

id,name
00123,Alex
9007199254740993,Sam

Expected values (spacing may differ)

[
  {"id": "00123", "name": "Alex"},
  {"id": "9007199254740993", "name": "Sam"}
]

Keep the right types downstream

All CSV fields remain strings in this tool, not just IDs. A value such as false stays "false", and an empty cell becomes an empty string rather than null. If an API needs a numeric quantity, convert that specific field downstream after checking its rules.

Do not turn every numeric-looking field into a number automatically. JavaScript cannot exactly represent every large integer. Quote long IDs in JSON before using the reverse converter.

Watch the spreadsheet import step

CSV does not store column types. Even a correctly generated CSV can be reinterpreted when opened in another application. Import identifier columns as Text rather than relying on automatic detection.

UTF-8 BOM is an encoding aid, not a type declaration. Spreadsheet-safe mode addresses certain formula-like text, not leading-zero preservation. Check the file's text and the receiving application's import settings separately.

References

General format references; LocalShift-specific behavior is documented and tested separately.

Try the tools