CSV to Zig struct
Paste a CSV with a header row. Every row is treated as a sample, so column types reflect the whole file, and the result parses with serde.zig as a slice of rows.
API responseSmallest int widths from observed range; auto enum suggestion; missing/null become optional.
id,customer,total,paid,shipped_at 1001,Alice,49.90,true,2026-03-02 1002,"Bob, Jr.",12.5,false, 1003,Carol,230,true,2026-03-04
Order.zig const serde = @import("serde");
pub const Order = struct {
id: u16,
customer: []const u8,
total: f64,
paid: bool,
shipped_at: ?[]const u8 = null,
};
Diagnostics
2 warningsField decisions
Why each field got its type. Click a row to see it in the input; edit to override.
struct Order $ 5 fields
How CSV columns become fields
- The header row names the fields; each data row is one observation.
- An empty unquoted cell makes the column optional, which is what serde.zig's CSV reader needs to accept it.
- Quoted cells stay strings; unquoted cells become integers, floats or booleans only when every value parses.
- Rows shorter than the header are reported, because serde.zig rejects them by default.
Questions
- How do I read a CSV file in Zig?
- With serde.zig:
serde.csv.fromSliceManaged([]const Order, allocator, input)returns every row. The More menu copies this helper. - Why is a column optional?
- At least one row left it empty. Click the field in the table to see how many rows had a value.