TOON to Zig struct
Paste a TOON document. zigshape decodes it with the reference implementation and writes Zig structs that serde.zig reads with serde.toon.
API responseSmallest int widths from observed range; auto enum suggestion; missing/null become optional.
users[3]{id,name,role,active}:
1,Alice,admin,true
2,Bob,editor,false
3,Carol,viewer,true
page: 1
Directory.zig const serde = @import("serde");
pub const Directory = struct {
users: []const User,
page: u8,
};
pub const User = struct {
id: u8,
name: []const u8,
role: []const u8,
active: bool,
};
Field decisions
Why each field got its type. Click a row to see it in the input; edit to override.
struct Directory $ 2 fields
struct User $.users[*] 4 fields
How TOON maps to Zig
- Tabular arrays like
users[3]{id,name}:become a slice of a generated struct. - Inline arrays like
tags[2]: a,bbecome slices of scalars. - Indented objects become nested structs, as with YAML.
Questions
- How do I parse TOON in Zig?
serde.toon.fromSliceManaged(Directory, allocator, input)from serde.zig.- How is TOON told apart from YAML?
- By its array headers such as
items[2]:. A TOON document without one reads the same as YAML, so either format gives the same struct.