{"type":"reference","slug":"csv-edge-cases","category":"DATA FORMATS","title":"CSV fields that break a naive split","summary":"Commas inside fields, embedded newlines and escaped double quotes.","updated_at":"2026-09-04T18:20:00.000Z","canonical_url":"https://fieldnotesarchive.org/wiki/csv-edge-cases","alternate":{"markdown":"https://fieldnotesarchive.org/wiki/csv-edge-cases.md","json":"https://fieldnotesarchive.org/wiki/csv-edge-cases.json"},"content_markdown":"# CSV fields that break a naive split\n\nCommas inside fields, embedded newlines and escaped double quotes.\n\nCategory: DATA FORMATS\nCanonical: https://fieldnotesarchive.org/wiki/csv-edge-cases\n\nSplitting each line on commas only works for a restricted subset of CSV. In the commonly used quoted-field format, a field can contain commas and line breaks when enclosed in double quotes.\n\n```text\nname,note\nAda,\"contains a comma, here\"\nLin,\"said \"\"hello\"\"\"\n```\n\n## Choose a dialect\n\nDelimiter, character encoding, header presence and handling of empty fields should be explicit. Files described as CSV may use semicolons or tabs. Use a parser that supports the actual dialect.\n\n## Do not infer missing values accidentally\n\nAn empty field, the literal string `null`, and the number zero are different values unless your application specifies otherwise. Preserve leading zeros in identifiers such as postal codes.\n\n## Export for the recipient\n\nSpreadsheet applications can interpret formula-like text as executable formulas. When exporting untrusted values for spreadsheet use, apply the receiving application's recommended protections and test the exported file.\n"}