How to convert CSV to JSON without losing leading zeros
Learn how CSV to JSON conversion can preserve leading zeros in identifiers and how to validate exported records.
Published by Rapid File Converter · Editorial policy
How to convert CSV to JSON without losing leading zeros: practical example
Use a row with id 001 and name bolt. Verify the JSON identifier is a string, not numeric 1. Test the sample row with the CSV to JSON converter and inspect the identifier in the resulting JSON.
Preserving CSV identifiers in JSON
When converting CSV to JSON, treat account codes and part numbers as strings rather than numeric quantities. Verify that leading zeros survive parsing in the destination application.
Decide which columns are identifiers
A CSV field containing 00124 could represent a part number, postal code or quantity. The characters alone do not establish its meaning. Preserve identifiers as strings, even when they contain only digits. Convert quantities to numbers only when the receiving system requires that type. The browser converter preserves CSV values as strings rather than guessing their intended types.
A worked inventory example
Consider a CSV with header id,name,qty and a row 001,bolt,4. A string-preserving JSON representation is {"id":"001","name":"bolt","qty":"4"}. If the destination schema requires a numeric quantity, explicitly change qty to 4 after validating the field. Changing id to numeric 1 would lose information that cannot reliably be recovered later.
Handle delimiters and quoted fields
A description such as Bolt, zinc plated contains a comma that belongs inside the field. In comma-separated CSV it must be quoted. Embedded double quotes are normally escaped by doubling them. A parser that simply splits each line at commas will misinterpret these records. Check the detected delimiter and inspect descriptions containing punctuation or line breaks.
Check empty values and headers
An empty field is not necessarily a missing value or numeric zero. Agree on the destination convention before transforming it. Duplicate column names can cause ambiguous JSON object keys; rename them deliberately in the source. Compare the number of records and field names with the original, allowing for the header row.
Avoid spreadsheet type conversion
Opening CSV directly in a spreadsheet can remove leading zeros, interpret identifiers as dates or display long numbers in scientific notation. Import the file with identifier columns explicitly set to text. If the spreadsheet has already altered a value, return to the original export rather than guessing the missing characters.
Validate the destination schema
Parse the JSON and inspect representative records including the first and last rows, blank fields and identifiers. Confirm that strings, numbers and null values match the receiving application's schema. Keep the original CSV and document any intentional type changes so that the conversion can be repeated consistently.
Distinguish identifier fields from quantities
An inventory record can contain code 001 and quantity 4. The code should remain a string even if it consists entirely of digits. The quantity may need conversion to a number for arithmetic. Define those rules explicitly in the receiving application instead of applying automatic numeric conversion to every field.
Test difficult records before importing
Include a quoted description containing a comma, an empty field and a non-ASCII name in a sanitized test file. Parse the resulting JSON and compare each field against the expected value. Check null handling and record counts. Keep a copy of the source and the agreed destination schema.
Which format should you choose?
Use strings for identifiers and explicit numeric conversion only for fields that represent quantities.
What to check
- Download the inventory sample
- convert
- inspect quoted identifiers
- compare record counts and field names.
Troubleshooting
If 001 becomes 1 in a spreadsheet, import the identifier column as text. Formatting cannot reliably restore unknown leading zeros.
Further reading
RFC 8259 JSON · Our conversion methodology
Try it with an example
The sample inventory contains 001 and 002. These are identifiers, not quantities. JSON strings preserve the leading zeros; converting them to numbers changes their meaning.
Related converters: CSV to JSON · JSON to YAML
What to keep in mind
Check duplicate headers, empty fields and delimiter detection before importing.