YAML to Go Converter - Generate Go Structs from YAML
Free Go YAML Struct Generator with JSON and YAML Tags
Convert YAML configuration to Go structs with json and yaml tags. Generate type-safe Go code from YAML online.
YAML to Go, convert yaml to go, go yaml struct, yaml to golang, go struct generator, yaml parser go, go config struct, yaml tags go
How to Convert YAML to Go Structs - Complete Step-by-Step Guide
Input Your YAML Configuration
Start by pasting your YAML configuration file. This tool is perfect for converting Kubernetes configs, Docker Compose files, application settings, CI/CD pipelines, or any YAML-based configuration into type-safe Go structs.
Example: YAML Configuration Input
Here's a typical YAML configuration for an application:
server:
host: localhost
port: 8080
timeout: 30
tls:
enabled: true
cert_file: /path/to/cert.pem
database:
host: db.example.com
port: 5432
username: admin
password: secret123
max_connections: 100
features:
- authentication
- logging
- metricsAutomatic Type Detection & Struct Generation
The converter analyzes your YAML structure and automatically generates properly typed Go structs:
Example: Generated Go Struct Output
The YAML config above becomes these type-safe Go structs:
package main
// Read a file with gopkg.in/yaml.v3: var cfg Config; err := yaml.Unmarshal(data, &cfg)
type Config struct {
Server Server `json:"server" yaml:"server"`
Database Database `json:"database" yaml:"database"`
Features []string `json:"features" yaml:"features"`
}
type Server struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Timeout int `json:"timeout" yaml:"timeout"`
TLS TLS `json:"tls" yaml:"tls"`
}
type Database struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
MaxConnections int `json:"max_connections" yaml:"max_connections"`
}
type TLS struct {
Enabled bool `json:"enabled" yaml:"enabled"`
CertFile string `json:"cert_file" yaml:"cert_file"`
}Customize Your Go Code Generation
Fine-tune the output to match your project's coding standards and requirements:
Export and Integrate Into Your Go Project
Drop the structs into your project and load the file with gopkg.in/yaml.v3:
Frequently Asked Questions
How does the converter pick the Go field types?
From how each value is written in the YAML, not from a rounded JavaScript number. Whole numbers become int, or int64 when they don't fit in 32 bits, so a 19-digit ID like 8901240544102066246 keeps every digit. Values above int64 become uint64, and anything longer than 64 bits becomes string. 14.50 becomes float64, true and false become bool, and quoted text, dates and numbers with a leading zero like 00501 stay string. Every item in a list is looked at, so a key that only some items have becomes a pointer (*int, *bool), and a list that mixes 1 and 2.5 becomes []float64.
Can I use this for Kubernetes config files?
Yes, for the files you actually have. Paste a Deployment, a Helm values.yaml or a Compose file and you get structs for the keys in that file. A file with several documents separated by --- gets one set of structs that covers all of them, and a list at the top level gets a struct for one item. If you're writing an operator against the full Kubernetes API, the official types in k8s.io/api are the better choice, since they cover fields your file leaves out.
What YAML libraries work with the generated structs?
The code is checked against gopkg.in/yaml.v3: the yaml tags hold each original key, so yaml.Unmarshal(data, &cfg) reads every field, including keys like first-name or max_connections that don't look like Go names. gopkg.in/yaml.v2 and github.com/goccy/go-yaml read the same yaml:"..." tags. With json tags switched on, the same structs also work with encoding/json.
How are YAML anchors and aliases handled?
Aliases are followed, so the structs describe the data after every *name has been replaced by what its &anchor points to. The anchors themselves don't appear in the Go code, because yaml.v3 resolves them when it reads the file.
Is my YAML sent anywhere?
No. The YAML is read and the Go code is written in your browser, so nothing is uploaded, and nothing is kept: reload the page and the editor starts empty.
External Resources & Documentation
Most popular YAML parsing library for Go with struct marshaling support
Official YAML specification and language reference
Official documentation for the yaml.v3 Go package
Guide to working with Kubernetes YAML configurations
High-performance YAML parser with better error messages
Official Go blog explaining struct tags for YAML and JSON
Go client for Kubernetes with extensive YAML struct examples
Working with YAML templates in Helm for Kubernetes
Struct validation library compatible with YAML-loaded data
Related Tools
JSON to Go
Convert JSON data to Go structs with json tags
JSON Schema to Go
Generate Go types from JSON Schema with validation
TOML to Go
Convert TOML configuration to Go config structs
XML to Go
Convert XML data to Go structs with xml tags
CSV to Go
Convert CSV data to Go structs with field mapping
TypeScript to Go
Convert TypeScript interfaces and types to Go structs