Keep leading zeros and columns when converting CSV

Handle delimiters, quoting, decimal commas and identifier columns when moving CSV between spreadsheets and JSON.

Define the columns before importing

CSV is plain text and does not carry spreadsheet cell types. A postal code such as 00123 can become 123 if a spreadsheet guesses it is a number. Import the file through the spreadsheet’s text or CSV import dialogue and set identifier columns to text. Do not rely on double-clicking the file. Keep the raw CSV so a mistaken import can be repeated without reconstructing lost digits.

Check separators and quoting

A comma-separated file can contain commas inside a quoted field: "Paris, France" is one value. In regions using decimal commas, semicolons are also common field separators. Read the actual delimiter rather than inferring it from the .csv extension. A quoted field may contain a line break, so counting visible lines is not always the same as counting records. Inspect a row with punctuation before processing the whole file.

Use a small verification sample

Include a leading-zero code, an accented name, a date, a negative amount and a blank value in the sample. Compare the row count and column names after conversion to JSON. Check whether blank, zero and missing values are distinguishable in the receiving application. For financial data, reconcile totals before and after conversion. Numbers formatted for display should not silently replace the original numeric value.

Do not confuse CSV cleanup with PDF extraction

A PDF table must first be extracted or recognized before CSV rules apply. Fix merged headings, wrapped cells and repeated page headers at that stage. Dev Bench converts an existing CSV to JSON; it does not extract tables from PDFs. If a value begins with =, +, - or @, inspect how a spreadsheet will interpret it before opening an untrusted export, since some applications treat such text as a formula.

Related tools