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
- id: C1 claim: The csv package reads and writes comma-separated values files. source: S1 evidence: "Package csv reads and writes comma-separated values"
- id: C2 claim: The supported format is RFC 4180, except Writer defaults to LF. source: S1 evidence: "supports the format described in RFC 4180"
- id: C3 claim: Writer uses LF instead of CRLF by default. source: S1 evidence: "Writer uses LF instead of CRLF as newline character by default"
- id: C4 claim: White space is considered part of a field. source: S1 evidence: "White space is considered part of a field"
- id: C5 claim: The source comments also describe RFC 4180 support. source: S2 evidence: "described in RFC 4180"
- id: C6 claim: The source comments say blank lines are ignored. source: S2 evidence: "Blank lines are ignored"
Sources
- [S1] encoding/csv package reference. Go. https://pkg.go.dev/encoding/csv . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] encoding/csv/reader.go source. Go. https://go.dev/src/encoding/csv/reader.go . License: BSD-3-Clause. Accessed 2026-11-23.
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
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.},
}
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.
- go-encoding-csv.schema.json (schema; CC-BY-4.0)
- go-encoding-csv.table.json (table; CC-BY-4.0)
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.