csv module

Read CSV either as raw rows (list of lists) or as records (list of maps keyed by header). Write CSV from rows.

import "csv" as csv;
import "io"  as io;

var text = io.read_file("users.csv");
var rows = csv.parse(text);             // [["id","name"], ["1","Alice"], ...]

var records = csv.parse_records(text);  // [{id: "1", name: "Alice"}, ...]
print(records[0].name);                 // Alice

var out = csv.stringify([["id","name"], [1,"Alice"], [2,"Bob"]]);
io.write_file("out.csv", out);

API

FunctionDescription
csv.parse(text) → list of listsEach inner list is one row's cells.
csv.parse_records(text) → list of mapsFirst row treated as headers; subsequent rows become maps keyed by header.
csv.stringify(rows) → stringrows is a list of lists. Cells are coerced to strings and quoted when needed.

See also

  • json — when JSON fits your data better.