Production-ready CSV parser and stringifier handling RFC 4180 rules
ez install csv
| Package | Range |
|---|---|
| No dependencies. | |
A robust CSV (Comma-Separated Values) parser and stringifier for EZ, fully supporting RFC 4180 rules, including:
"")
This library is included in the standard ezlib packages. Import it via:
use "csv"
parse(csvString)Converts a CSV string into an Array of Dicts. The first row of the CSV is used as the keys for each dictionary.
dataStr = "name,age\nAlice,30\nBob,25"
rows = csv.parse(dataStr)
out rows[0]["name"] # "Alice"
stringify(dataArray)Converts an Array of Dicts back into a CSV string. Automatically escapes fields that contain quotes, commas, or newlines.
data = [
{ "name": "Alice", "quote": "She said, \"Hello!\"" },
{ "name": "Bob", "quote": "No quote" }
]
csvStr = csv.stringify(data)
# name,quote
# Alice,"She said, ""Hello!"""
# Bob,No quote
read(filePath)Reads a CSV file directly from disk and parses it into an Array of Dicts.
data = csv.read("data.csv")
write(filePath, dataArray)Writes an Array of Dicts directly to a CSV file.
success = csv.write("output.csv", data)| Version | Size | Downloads | Published |
|---|---|---|---|
1.0.0 |
5.7 KB | 0 | 1 hour ago |
sha256 c5980cb9c686ba20ccacbc9239403a042402c3851bc365efa81124271df2c9dd