csv guide

Keep Leading Zeros When Converting CSV to JSON

Preserve identifiers such as 00127 with a reproducible CSV sample, expected JSON and checks for upstream spreadsheet conversion.

Published September 7, 2026 by SOLVEOZA Editorial · Updated October 9, 2026

Quick answer

Treat identifiers as text throughout the workflow. SOLVEOZA CSV to JSON preserves cell values as strings, including leading zeros. If a spreadsheet already changed 00127 to 127, the converter cannot know which digits were lost.

Reproduce the loss with a harmless sample

Use the following invented three-row CSV with Comma and First row as headers. The first column is an identifier, while the second is a quantity. In SOLVEOZA both are initially preserved as strings. The sample deliberately includes 00123, 00000 and an empty code so you can distinguish padding, a zero-valued code and missing data.

After conversion, the codes should be the JSON strings "00123", "00000" and "". Now consider a downstream numeric cast: Number("00123") is 123, Number("00000") is 0, and Number("") is also 0. A careless conversion destroys not only padding but also the distinction between an all-zero code and a missing code.

Synthetic CSV — preserve each code as text
code,quantity
00123,2
00000,0
,5
Expected JSON before any downstream numeric conversion
[
  { "code": "00123", "quantity": "2" },
  { "code": "00000", "quantity": "0" },
  { "code": "", "quantity": "5" }
]

Why adding zeros back can invent an identifier

Once 00123 has become 123, several originals are possible: 123, 0123, 00123 and longer padded strings. A converter cannot know which one was intended. Padding every value to five characters is valid only when a verified data contract says the identifiers are exactly five characters long.

Recover from an untouched export or authoritative source where possible. If a fixed-width rule is documented, apply it deliberately and validate the result against known identifiers. Do not use a display mask as proof that exported values have been repaired; inspect the raw output again.

Choose a recovery action from the evidence you still have
Available evidenceSafe next stepDo not assume
Original CSV still contains 00123Convert the untouched copy with text preservationThat the spreadsheet display equals the exported value
Only 123 remains; no width ruleRequest the original or authoritative identifierHow many zeros were lost
Verified five-character identifier contractPad under that rule and validate against source recordsThat quantities use the same rule
Empty code became numeric 0Return to a source retaining missing-value informationThat 0 identifies the original missing record

Make a small handoff contract

State which columns are identifiers, whether empty values are permitted, and whether width is fixed. Keep the original export read-only while testing. Convert a small invented sample first, compare row count and values, then use the same settings on permitted data. Avoid placing private customer records into a shared example.

SOLVEOZA preserves cells as strings; it does not decide the receiving system's schema. If quantity must become a number, convert that field explicitly downstream while leaving code as text. Before import, check that the receiving program will preserve quoted identifier strings instead of guessing types again.

A code is not necessarily a number

A product identifier uses digits to name an item. Its width may be meaningful, so 00127 and 127 need not identify the same thing. A quantity is different: padding does not usually change the amount it represents.

Decide which columns are identifiers before importing. Record that decision in the handoff rather than expecting another program to infer it from a few rows.

Inspect the original CSV before conversion

Open a copy in a plain-text editor. If 00127 is still present in the raw text, those characters are available to preserve. If it already says 127, investigate the upstream export first.

This invented inventory sample includes three codes and one deliberately empty code. An empty field is not the digit zero.

Original CSV — comma delimiter, first row as headers
code,label
00127,Notebook
00008,Pencil
01000,Folder
,Unassigned

Convert without guessing types

In CSV to JSON, choose Comma and First row as headers. Convert the sample and compare it with the expected result. Cell values remain strings: the first code is quoted as 00127 rather than stored as the number 127.

Check that there are four rows. Inspect every code before passing the output onward, and do not convert numeric-looking identifiers merely to make the JSON shorter.

Expected JSON — identifiers remain strings
[
  {
    "code": "00127",
    "label": "Notebook"
  },
  {
    "code": "00008",
    "label": "Pencil"
  },
  {
    "code": "01000",
    "label": "Folder"
  },
  {
    "code": "",
    "label": "Unassigned"
  }
]

Find the stage that changed the value

Compare the original export, the spreadsheet import and the final JSON. If the raw CSV retained the zeros but a later export lost them, the spreadsheet step is the place to investigate. Re-running JSON conversion cannot reverse an upstream edit.

Follow one identifier through the handoff
StageValueMeaning
Raw CSV00127Original characters available
JSON output"00127"Text identifier preserved
Numeric interpretation127Width information discarded
Display-only mask00127 on screenVerify exported text; appearance alone is not evidence

When Excel is part of the workflow

Microsoft documents text import and formatting options for preserving zeros. In supported Excel versions, use Data → From Text/CSV and inspect the column type during import. Do not assume that opening a CSV automatically preserves identifiers. Menus vary by version and platform.

Check the exported file in a text editor after the spreadsheet step. A custom cell format changes appearance; it does not establish what was in the original data. For long identifiers, check all digits as well. The instructions here reference Microsoft documentation, not an interactive test of every Excel version.

Recover from the source, not a guessed width

Padding 127 to five places is justified only when an authoritative rule says the code has five digits. Without that rule, 0127, 00127 and 000127 are different possible originals.

Request a text-preserving export or compare with a trusted source list. Keep identifiers separate from quantities, and document whether the receiving application expects empty strings, missing fields or null values.

Methodology

  1. Use four synthetic rows, including three padded product codes and an empty code.
  2. Run the existing CSV converter with comma and first-row settings.
  3. Compare row count and values with the expected independent object.

Limitations

  • Lost identifiers cannot be reconstructed from this conversion.
  • Spreadsheet instructions depend on version and platform.
  • Receiving applications may require different field types or null handling.

Sources

Original SOLVEOZA examples and guidance checked against the references below. Sources explain the rules; they are not endorsements of this site.

FAQ

Do quoted CSV values protect zeros in every spreadsheet?

No. Importers may infer types. Verify raw values and the chosen import type.

Does the converter infer numbers?

Current SOLVEOZA CSV conversion keeps cell values as strings. Check the receiving application before deliberately converting selected fields.

What happens to an empty code?

In this fixture the empty cell becomes an empty string, not zero or null.

Can I restore deleted zeros?

Only with a trustworthy source or explicit format rule. The converter does not guess missing width.

Continue the task