YAML to Zig struct

Paste a YAML config and zigshape produces a Zig struct for it. The Strict config preset turns observed scalars into field defaults, so a missing key still yields a usable value.

Target

Strict configConservative u64; enums off; observed scalar values become Zig defaults — best for TOML/YAML configs.

# Service name shown in logs
name: myapp
replicas: 3
labels:
  app: api
  tier: backend
ports:
  - 8080
  - 8443
YAML 10 lines 113 B Drop files here to add samples
Config.zig
pub const Config = struct {
    name: []const u8 = "myapp",
    replicas: u64 = 3,
    labels: Labels,
    ports: []const u64,
};

pub const Labels = struct {
    app: []const u8 = "api",
    tier: []const u8 = "backend",
};
loading zig fmt 2 structs · 6 fields 11 lines

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 Labels $.labels 2 fields

YAML details zigshape handles

  • Anchors, aliases and << merge keys resolve before inference, so the struct reflects the effective document.
  • YAML 1.2 scalars: yes and no stay strings, matching serde.zig's default reader.
  • Key comments become /// doc comments with Doc comments from YAML in Options.
  • Multi-document YAML uses the first document and says so.

Questions

How do I read YAML in Zig?
The standard library has no YAML parser. Use serde.zig: switch the target to serde.zig and call serde.yaml.fromSliceManaged(Config, allocator, input).
Are YAML anchors and merge keys supported?
Yes. They are resolved before types are inferred, so a merged map produces one struct with every inherited field.
Can I keep the comments from my YAML?
Turn on Doc comments from YAML in Options (or pass --with-doc-comments to the CLI) and each commented key gets a /// line.