csv
Parse and emit CSV/TSV following RFC 4180 with Excel-pragmatic extensions. Rows round-trip between strings and CXDM records: a header dialect yields maps keyed by header strings, while a headerless dialect yields positional arrays. Dialect handling covers delimiter, quote, escape, and line-terminator, and cell values are strings unless coerced via a schema. Distinct from the cross-format CLI conversion path — this is the in-program library form.
csv:parse
[$csv:parse] -> [sequence any] — Parse CSV with the default headered dialect into a sequence of maps keyed by header strings.
[?lib 'cx-stdlib/csv']
[$count [$csv:parse "email,first_name,score\nalice@example.com,Alice,87"]]
1
csv:parse-with-dialect
[$csv:parse-with-dialect] -> [sequence any] — Parse a string with a named or fully-specified dialect; the row shape follows the dialect header setting.
[?lib 'cx-stdlib/csv']
[?let [= $rows [$csv:parse-with-dialect "a\tb\n1\t2" [dialect [name "tsv"]]]]
[= $row [$nth $rows 1]]
$row/a]
'1'
csv:parse-with-schema
[$csv:parse-with-schema] -> [sequence any] — Parse CSV and coerce schema-named columns to typed values; absent columns stay strings.
[?lib 'cx-stdlib/csv']
[?let [= $rows [$csv:parse-with-schema "score\n87" {score: :int}]]
[= $row [$nth $rows 1]]
$row/score]
87
csv:emit
[$csv:emit] -> string — Emit a sequence of record rows as CSV using the default dialect, quoting and escaping per RFC 4180.
[?lib 'cx-stdlib/csv']
[$csv:emit ({a: "1", b: "2"})]
'a,b
1,2
'
csv:emit-with-dialect
[$csv:emit-with-dialect] -> string — Emit record rows as CSV/TSV using a named or fully-specified dialect.
[?lib 'cx-stdlib/csv']
[$csv:emit-with-dialect ({a: "1", b: "2"}) [dialect [name "tsv"]]]
'a b
1 2
'
csv:dialects-builtin
[$csv:dialects-builtin] -> map — Return the seven built-in dialects (csv, tsv, psv, excel, excel-tab, unix, headless) keyed by name.
[?lib 'cx-stdlib/csv']
[$count [$keys [$csv:dialects-builtin]]]
7