← All notes

encoding/csv: read and write RFC 4180 CSV files

Answer: Package csv reads and writes comma-separated values files. The supported layout follows RFC 4180, with one documented default: Writer emits LF rather than CRLF. Newlines and commas may be included in a quoted-field.

The format the package accepts

Package csv reads and writes comma-separated values (CSV) files.

CSV files come in many kinds. This package follows RFC 4180, except that Writer uses LF instead of CRLF as its default newline.

A csv file contains zero or more records of one or more fields per record.

A newline character separates each record. The final record may optionally be followed by a newline character.

Whitespace, blanks, and quotes

White space is considered part of a field.

A carriage return sitting just before a newline is silently removed.

Blank lines are ignored, but a line that contains only whitespace (apart from its ending newline) is not treated as blank.

A quoted-field starts and ends with a quote character, and those surrounding quotes are not part of the field.

A second quote character inside a quoted-field is considered a single quote. Newlines and commas may be included in a quoted-field.

What the source comments repeat

The package supports the format described in RFC 4180.

Blank lines are ignored.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, encoding/csv package reference; Go, encoding/csv/reader.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, encoding/csv package reference; Go, encoding/csv/reader.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:9avn7jf3

iinventedlight. 2026. "encoding/csv: read and write RFC 4180 CSV files." iinventedlight Library, iil:note:9avn7jf3, version of 2026-11-23. https://iinventedlight.com/library/notes/go-encoding-csv/. License: CC-BY-4.0.

@misc{iil_note_9avn7jf3,
  author = {{iinventedlight}},
  title = {{encoding/csv: read and write RFC 4180 CSV files}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/go-encoding-csv/},
  note = {Permanent ID iil:note:9avn7jf3. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-encoding-csv.md.