data.formats
read and write JSON and CSV text
Turns text into values and values back into text. Parsing a JSON or CSV string gives lists and maps you can work with, and writing does the reverse.
Tags: parsing, formatting
from_jsonread JSON text into zil values: objects become maps, arrays lists, and null nilto_jsonv as JSON textfrom_csvread CSV (comma-separated) textto_csvCSV text from a table, a list of maps, or a list of lists
Functions
Section titled “Functions”from_json
Section titled “from_json”from_json(s: str) -> any
read JSON text into zil values: objects become maps, arrays lists, and null nil
1"\{\"a\": [1, 2.5, null]}".from_json{a: [1, 2.5, nil]}to_json
Section titled “to_json”to_json(v: any) -> str
v as JSON text
Values JSON has no type for, like quantities, fractions and dates, become strings
1{a: [1, nil], b: 5 km}.to_json"{\"a\":[1,null],\"b\":\"5 km\"}"See also from_json
from_csv
Section titled “from_csv”from_csv(s: str, header: bool = true) -> table|list
read CSV (comma-separated) text
The first row is taken as column names and the result is a table. Pass false if there’s no such row, to get a list of rows. Numbers become numbers and empty cells nil
1"name,n\nx,1".from_csvtable([{name: "x", n: 1}])2"1,2\n3,4".from_csv(false)[[1, 2], [3, 4]]to_csv
Section titled “to_csv”to_csv(rows: table|list) -> str
CSV text from a table, a list of maps, or a list of lists
Cells with commas or quotes are quoted
1[{a: 1, b: "x,y"}].to_csva,b
1,"x,y"
2[[1, 2], [3, 4]].to_csv1,2
3,4
See also from_csv
More examples
Section titled “More examples”formats
Section titled “formats”1# read JSON and add up a list in it2"\{\"a\": [1, 2]}".from_json.a.sum33# read CSV and add up a column4"name,n\nx,1\ny,2".from_csv.n.sum3Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.