CSV / JSON

Keep 00123 as 00123 when converting CSV to JSON

A postal-code example with quoted commas, multiline cells and an explicit all-strings conversion policy.

A reproducible software example using fictional data. Source references and conversion limits are included below.

A postal code is an identifier, even when it contains only digits. The string 00123 and the number 123 are different data. A converter that guesses types can erase information before you notice. This example makes the choice explicit.

The sample file

name,postal_code,notes
Alex,00123,"Prefers email, not phone"
Sam,00456,"Line one
Line two"

There are two data records. The comma inside Alex’s notes belongs to a cell, and Sam’s note contains an actual line break. Splitting the source on commas or counting physical lines would produce the wrong structure.

Run the conversion

  1. Open CSV ↔ JSON and select CSV to JSON.
  2. Use the comma delimiter and load the example.
  3. Select Run conversion. Read the resulting records before copying or downloading them.
[
  {"name":"Alex","postal_code":"00123","notes":"Prefers email, not phone"},
  {"name":"Sam","postal_code":"00456","notes":"Line one\nLine two"}
]

SyntaxPad intentionally keeps every CSV cell as a JSON string. That includes 00123, an empty cell, true and 3. It does not guess a column’s schema from the first few rows. If your application needs a numeric quantity, perform that conversion explicitly after checking the field’s meaning.

Check the boundaries

Headers become property names. Duplicate headers are rejected because two columns named id cannot safely become the same property in one record. Empty headers and rows with the wrong number of cells also produce an error. Empty physical lines are skipped, while a row containing delimiters still represents cells.

On the reverse trip, JSON must be a non-empty array of objects. The output uses the union of their keys as headers. Nested objects and arrays are stored as JSON text inside a single cell; they are not expanded into extra rows. Missing fields and null become empty cells, so this reverse conversion cannot distinguish them. CSV is a table format, not a complete replacement for JSON’s type system.

A quick acceptance check

Confirm two records, the exact postal codes, one notes field per record and the preserved line break. When opening the CSV in a spreadsheet, import the postal-code column as text: even a correctly written CSV cannot force every spreadsheet’s automatic type detection. The spreadsheet export protection option guards formula-like cells; it does not control postal-code inference.

Reference: RFC 4180: CSV quoting and records. The sample names and data are fictional.

Try the same steps

Open CSV ↔ JSON and load the example to get started.