Skip to content
Fieldnotes ArchiveCOMPUTING · DATA · WORKING NOTES

DATA FORMATS

CSV fields that break a naive split

Commas inside fields, embedded newlines and escaped double quotes.

Splitting 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.

name,note
Ada,"contains a comma, here"
Lin,"said ""hello"""

Choose a dialect

Delimiter, 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.

Do not infer missing values accidentally

An 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.

Export for the recipient

Spreadsheet 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.

Alternate formats: Markdown · JSON

Have a correction or a related observation? Leave a working note.

← Reference index