TOML to Zig struct
TOML configs convert into Zig structs. The Strict config preset turns observed scalar values into Zig defaults, so missing keys still produce a usable struct.
Strict configConservative u64; enums off; observed scalar values become Zig defaults — best for TOML/YAML configs.
title = "myapp" port = 3000 debug = false [database] host = "localhost" name = "main"
Config.zig pub const Config = struct {
title: []const u8 = "myapp",
port: u64 = 3000,
debug: bool = false,
database: Database,
};
pub const Database = struct {
host: []const u8 = "localhost",
name: []const u8 = "main",
};
Field decisions
Why each field got its type. Click a row to see it in the input; edit to override.
struct Config $ 4 fields
struct Database $.database 2 fields
TOML structures zigshape handles
- Top-level keys and
[tables]become fields and nested structs. - Inline tables become nested structs too.
[[arrays of tables]]become slices of a generated struct.- Dates come through as
[]const u8.
Questions
- How do I parse TOML in Zig?
- Use serde.zig:
serde.toml.fromSliceManaged(Config, allocator, input). serde.zig expects a table at the root, which is what a TOML file is. - Are large integers supported?
- serde.zig parses TOML integers as
i64, so values above its range can't be read even when the field isu64.