Preventing Leading-Zero Loss & Formula Injection When Converting CSV and JSON
Moving tabular data between CSV exports and JSON records looks trivial until postal codes like 00123 become 123 or a user comment starting with = triggers a spreadsheet formula. Learn how to convert cleanly.
Why postal codes, SKUs, and phone numbers lose leading zeros
When a converter automatically guesses data types—turning "00123" into the JSON number 123—or when a spreadsheet opens an unformatted CSV file, leading zeros vanish silently. Postal codes, employee IDs, bank routing numbers, and product SKUs are identifiers, not quantities you add or multiply.
Keeping all CSV fields as explicit JSON strings ("code": "00123") preserves every leading zero, hyphen, and formatting character across imports.
What CSV formula injection is and why spreadsheet-safe export matters
Desktop spreadsheet apps evaluate cells starting with =, +, -, or @ as active formulas. If untrusted user input—such as a customer note containing =HYPERLINK(...) or =CMD|...—is exported to CSV and opened by a staff member, the spreadsheet may attempt to run an unintended formula.
Spreadsheet-safe export neutralizes risky prefixes by prepending an apostrophe (for example, '=1+1) so the cell is treated as literal text. Always keep this protection enabled for external or user-submitted data, and inspect imported columns carefully.
Handling commas, newlines, and quotation marks inside CSV cells
Valid RFC 4180 CSV wraps any cell containing a comma, double quote, or line break in double quotes, and escapes embedded quotes by doubling them (""). Ensure every row has the exact same column count and that header names are nonempty and unique before converting to JSON.
Clean conversion workflow for small datasets
Use CreamTools CSV ↔ JSON Converter to switch between flat string JSON arrays and RFC-style CSV locally in your browser. If you need to verify nested JSON before flattening it, inspect its syntax in JSON Formatter first.
CSV & JSON conversion checklist
- Keep postal codes, phone numbers, and IDs as strings so leading zeros never disappear.
- Leave spreadsheet-safe export enabled whenever exporting user-supplied text to CSV.
- Check that CSV header rows have unique, non-empty names and equal column counts on every row.
- Double-check negative-looking strings and escaped quotes after importing into Excel or Sheets.
Try the related tools
Convert CSV and flat string JSON records locally, preserving postal codes and identifiers as strings.
Format, minify and validate JSON locally while preserving numeric tokens and rejecting duplicate keys.
Real-time Unicode character counter, sentence parsing, reading time, and social limit meters.