Files and data

Preserve leading zeros in identifiers

Keep identifiers as strings when leading zeros are meaningful. A code such as 00123 is not necessarily a quantity, and converting it to a number discards information.

Worked example

Node.js example · save as example.mjs and run node example.mjs

const record = {postalCode: "00123", count: 123};
const saved = JSON.stringify(record);
const restored = JSON.parse(saved);
console.log(restored.postalCode, typeof restored.postalCode);
console.log(Number(restored.postalCode));

How it works

The JSON string preserves the five-character code exactly, while numeric conversion produces 123. Treating identity and quantity as different types makes the correct behavior explicit at import, storage, and display boundaries.

Limits and mistakes

A CSV file has no enforced cell types, so a spreadsheet may still reinterpret a quoted code as numeric. Configure the import column as text or use a format with explicit types. Padding later cannot reliably recover unknown original widths.

Check the result

Expect 00123 string and then 123. Round-trip through the actual consumer, not only JSON.parse, before promising that an export preserves every identifier.

Sources

Reference documentation for the behavior used in this guide: