Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | text | yes | Media types: text/csv, text/plain; charset=utf-8 |
out | output | records | yes |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
header | boolean | true | no | |
delimiter | string | "," | no | |
fields | array | none | no | Member names when header is false. |
When to use it #
- A CSV file with a header row: every further row becomes a record with the header's names.
- A file without a header, or with
;between fields: name the members withfieldsand setdelimiter.
When to use something else
- Every value arrives as a string, exactly as written —
007stays"007". There is no type inference: follow withstd:castwhere you need numbers.
A tested example #
Nothing here is invented: this is the test “header row names the members and values stay strings” from the pipe's own portable test file, which every conformant runner must pass.
This test sets no parameters.
id,name
007,"Bond, James"{"id":"007","name":"Bond, James"}The same step as a node of a pipeline.yaml:
nodes:
csv-decode:
pipe: std:csv-decode
inputs:
in: {from: inputs.in}This input is not plain records. A standalone pipeline.yaml cannot declare the kind of its inputs, so this node belongs in a pipe whose manifest declares the input in with kind text, or after a node that produces that kind.
Run it #
The pipe runs on its own from a shell. The input is the test input above. The quickstart shows how to get the openflange command.
printf 'id,name\n007,"Bond, James"\n' | openflange run std:csv-decode{"id":"007","name":"Bond, James"}Executed with openflange 0.0.1 (go1.27.1 linux/amd64), built from commit 11cf8cc of the reference implementation; the output shown is what it printed, and it matches the test.
Notes from the manifest #
The pipe's manifest, OPENFLANGE.md, carries these notes.
Part of the OpenFlange standard library (std, version 0.1).
The explicit conversion from CSV text to records (it is never inserted
automatically). Decoding is streaming. Quoting follows RFC 4180: quoted
fields may contain the delimiter, doubled quotes ("") and line breaks.
Rows end with LF or CRLF; a final row without a line terminator is accepted;
a leading UTF-8 byte order mark is discarded. delimiter is exactly one
character.
header: true(default): the first row names the members; every later row becomes an object with those members in header order. Duplicate or empty header names fail withE_FORMAT.header: falsewithfields:fieldsnames the members.header: falsewithoutfields: every row becomes an array of strings.
Every value is a string, exactly as it appears after unquoting — nothing
is type-guessed, so 007 and 1.50 arrive intact and an empty field is
"". Use std:cast to convert members. A row whose number of fields differs
from the header (or from fields) fails with E_FORMAT. Empty input, or
only a header row, produces no records.
Limitations of this implementation: completely empty lines are skipped, and a CRLF inside a quoted field is read as LF.
Reference #
- Maturity
- Experimental
- Processing scope
record- Manifest version
0.1.0
- Normative definition: std:csv-decode in the standard library specification
- Manifest and tests: std/0.1/csv-decode in the specification repository