CSV File Format
The first row of the file must contain a header with the name of each column. the header follows the conventions below and the title of each column is considered a string and hence must be quoted.
The header row also determines the number of columns for every row in the reminder of the file. Should a row contain fewer or more columns than in the header – this is considered an error in the file.
Columns should be delimited by a pipe (| – 0x7C). This character is chosen because it is unlikely to occur in plain text and it makes it easy for a human to read the format and distinguish columns from each other.
Rows must be delimited by the Line Feed (LF – 0x0A) character. Note that this is not the default on Windows systems and old Macintosh machines. The reason LF is chosen is that this makes the files smaller (as compared with the Windows standard of CR+LF)
Data Type Representation
The subsections here describe details on how to represent common data types.
String values should be quoted using double quotes (” – 0x22). For example, the following is correct:
String Escape Sequences
If data contains quotes, LF or other reserved characters in text strings, the data itself should be escaped like this:
Decimals should be separated with period (. – 0x2E). Thousand separators should not be used. Zero padding should not be used either.
Representing Date and Time
Date and time should be represented using the ISO 8601 and RFC 3339 format. For reference, the format is:
Unless specified otherwise, times are assumed to be in UTC. Dates should use the Gregorian Calendar. Year should always include at least four digits.
- ISO 8601 WikiPedia entry on ISO 8601 (Since the ISO standard itself is behind a paywall)
- RFC 3339 Describes time zone and year offsets
- Gregorian Calendar A detailed description of the problems arising with dates before 1582.
Data about countries should use the ISO-3166-1 alpha-2 country codes instead of the country name.
- ISO-3166-1 WikiPedia entry on ISO 3166 (Since the ISO standard itself is behind a paywall)
- ISO Countries CSV file with all ISO-3166-1 countries, formatted like described on this page.
Currencies should be represented using the ISO-4217 currency codes. Bit coins can be represented using the code BTC.
- ISO-4217 on WikiPedia
The entire file should be encoded with UTF-8. This is the most compact format that allows representation of unicode while remaining reasonably compatible with ASCII.
The MIME type of CSV files is text/csv.