Data formats · real, tested code

Read and Parse a CSV File in Larzscript

Parse CSV text into rows, or straight into dicts keyed by header - including quoted fields with embedded commas.

csv.parse_dicts() keys every row by its header instead of by index, and raises a clear error the moment a row's field count doesn't match, instead of silently misaligning data three columns later.

larzscript pkg install csv

Code

import "csv" as csv

let text = "name,age,city\nAda,36,London\nBo,24,\"Paris, France\""
let people = csv.parse_dicts(text)
print(people[0]["name"], people[0]["age"])
print(people[1]["city"])
Output
Ada 36
Paris, France