How and where do you encode the header and charset parameters for CSV files?

478 views Asked by At

The CSV spec (RFC 4180) identifies header and charset parameters, but it strangely doesn't specify where they go, or how they're encoded. For header it says:

The "header" parameter indicates the presence or absence of the header line. Valid values are "present" or "absent".

But where does this go in a CSV file or stream? And where does charset go?

See section 3 of the spec for the parameters bit. The whole doc is only a couple of pages of actual content, as we might expect for a CSV spec, but it leaves out critical details. Note that I'm not asking about a web server-to-browser scenario where there'd be HTTP header fields for MIME type or charset, but rather the general case of CSV files and streams.

1

There are 1 answers

0
53epo On

Confirming that there really is nowhere in a CSV data file to put those metadata fields, either as a file or as a stream.

Those two fields are - as you mentioned - only for cases where a CSV file is being exchanged via a MIME aware protocol, such as HTTP.

Other formats have found different ways around the problem. E.g. JSON must be encoded using UTF-8. XML has an encoding in the prolog.