Developer Tools

Convert CSV to JSON while keeping leading zeros and line breaks

Convert a realistic CSV example with a 00123 identifier, quoted commas, escaped quotes and a multiline field. Check the expected JSON and a safe return to CSV.

Keep identifiers as strings

CSV carries fields and records; it does not define a universal field type system. A value such as 00123 might be a postal code, an order reference or a number. This converter keeps CSV fields as strings rather than guessing. That preserves leading zeros and stops values such as false or 2026-10-19 from changing type during import.

Quoted fields can contain commas, quotation marks and line breaks. A split on every comma or every line would corrupt those records. The basic quoting rules are described in RFC 4180; real exports can still use different delimiters or conventions.

Try quoted commas, quotes and a multiline note

  1. Open CSV ↔ JSON Converter and select CSV → JSON.
  2. Choose the comma delimiter and paste the complete sample, including the line break inside the last field.
  3. Convert. The result should contain one object with three string fields.
  4. Check the escaped newline \n in the JSON string. It represents one line break, not the two literal characters backslash and n in the original CSV.
CSV input — one data record across two lines
id,name,note
00123,"River, Lee","Said ""hello""
Second line"
Expected JSON
[
  {
    "id": "00123",
    "name": "River, Lee",
    "note": "Said \"hello\"\nSecond line"
  }
]

The CSV quotes around a field are syntax, so they do not become extra quotes around the JSON value. Two adjacent quotes inside a quoted CSV field represent one literal quote. The converter reports inconsistent column counts and duplicate or blank header names instead of quietly discarding data.

Convert back with the destination in mind

Swap the result, select JSON → CSV and convert again. For this example, the fields should retain their values even if line endings or optional quoting differ. A field containing a comma, a quote or a line break needs quoting in CSV.

The spreadsheet-safety option prefixes risky formula-like values with an apostrophe. It is useful when opening untrusted text in a spreadsheet, but it intentionally changes the exported field. Turn it off only when you understand the destination and need an exact text round trip. Nested arrays and objects also need an explicit serialization policy; CSV itself does not have nested cells.

If the result looks wrong

  • Everything is in one column: check whether the source uses semicolons or tabs instead of commas.
  • A multiline note becomes several records: check that the whole field is enclosed in matching double quotes.
  • A spreadsheet removes zeros after export: import that column as text. Preserving the CSV bytes cannot control a spreadsheet’s automatic type inference.
  • Line endings matter: open a UTF-8 file rather than pasting it. Browser textareas normalize pasted line endings; supported file imports retain the raw text until you edit it.

Use smaller batches for large datasets. This tool accepts up to 5 MiB of UTF-8 input, 100,000 rows and 2,000 columns, subject to nesting, value-count and output limits.