YAML to Go
Generate Go structs from a YAML sample.
YAML to Go – Structs for typed configuration
The YAML to Go converter generates Go structs from a YAML document. Paste your config.yaml, a Helm values file or a GitHub Actions workflow and get structs you can decode into with gopkg.in/yaml.v3, sigs.k8s.io/yaml or Viper.
How YAML maps to types
The document is parsed with the YAML 1.2 core schema: mappings become classes, sequences become lists, and plain scalars are typed as integers, floats, booleans, null or strings. Anchors and aliases are resolved before inference, comments are ignored, and quoted values such as "0042" stay strings. When a sequence contains several mappings, their keys are merged, so a key present in only some entries becomes optional.
Tags and libraries
The generated structs carry json:"..." tags. That works directly with sigs.k8s.io/yaml (used throughout the Kubernetes ecosystem), which converts YAML to JSON and then uses the JSON tags, and with Viper's mapstructure-style decoding after a simple find-and-replace. For gopkg.in/yaml.v3, replace json: with yaml: in the output — the key names and omitempty flags stay the same. Field names follow Go conventions, including initialisms such as URL, ID and TTL.
Options
Toggle omitempty for optional keys, use pointers to distinguish a missing value from a zero value (useful for defaults), switch timestamps to time.Time, and set the package name to match your project.
Typical uses
Typed application config for CLIs and services, parsing Docker Compose files or CI pipelines in tooling, reading Kubernetes custom resource examples, and replacing map[string]interface{} lookups with compile-time checked fields.
Tips
Durations such as 30s stay strings; change the field to time.Duration and parse it yourself if needed. Lists of mappings are merged, so include a few entries when keys vary between items.
Related tools
Validate your input with the YAML Validator, convert it with YAML to JSON, or generate structs from JSON with JSON to Go.
Frequently Asked Questions
Is my YAML uploaded anywhere?
No. The YAML parser and the code generator both run locally in your browser. You can disconnect from the network after the page loads and the converter keeps working.
Why are the tags json and not yaml?
The struct tags follow the JSON convention because sigs.k8s.io/yaml and many config loaders use them. For gopkg.in/yaml.v3 just replace json: with yaml: — the names are identical.
How are optional keys handled?
Keys missing from some items in a list, or set to null, become pointer fields with omitempty, so you can detect when a value was not configured.
Are YAML comments preserved?
No. Comments are ignored when parsing, so add doc comments to the generated struct fields yourself if you want to keep the explanations.