YAML to Go Converter
Convert YAML to Go struct with yaml tags instantly
YAML Input
Go Output
What is YAML to Go Converter?
This tool converts YAML data structures into Go structs with proper field names, types, and yaml struct tags. Go's static typing requires explicit type declarations, and this tool infers the correct Go types from your YAML values.
YAML keys are converted to PascalCase Go field names following Go conventions. Each field is annotated with a yaml:"key" struct tag for use with Go's popular YAML libraries like gopkg.in/yaml.v3. Type mapping: strings → string, integers → int, floats → float64, booleans → bool, lists → []interface{}.
This converter maps YAML scalar types to their Go equivalents and generates struct types with yaml struct tags for use with popular Go YAML libraries like gopkg.in/yaml.v3.
How to Convert YAML to Go
Follow these steps to generate a Go struct from your YAML data.
Paste or Upload Your YAML
Paste your YAML into the left panel, or click Upload to load a .yaml file. Click Sample for an example. Example YAML:
service:
name: my-api
port: 8080
replicas: 3
debug: false
tags:
- api
- backendClick Convert
There's no button to press: the right panel updates as you type, showing a Root struct plus one named struct per nested mapping, with exported field names and a yaml tag holding each original key.
Copy or Download the Go Code
Click Copy to copy the Go code to clipboard, or Download to save as a .go file. Import gopkg.in/yaml.v3 and use yaml.Unmarshal() to populate the struct.
When You'd Use This Tool
Kubernetes Config
Generate Go structs from Kubernetes YAML manifests for use with client-go or custom Kubernetes controllers.
App Configuration
Convert application YAML configuration files to Go config structs for type-safe config loading with yaml.v3.
API Contracts
Convert YAML API schema definitions to Go structs for use in HTTP handlers and API clients.
Infrastructure as Code
Convert Terraform or Ansible YAML variable files to Go structs for custom tooling.
Frequently Asked Questions
What Go types are inferred from YAML values?
string → string, whole number → int, decimal → float64, boolean → bool, date → string, null → interface{}, mapping → its own struct type. A list whose items share a type becomes a typed slice ([]string, []Step); a mixed or empty list becomes []interface{}.
Does it generate yaml struct tags?
Yes. Every field gets a yaml:"fieldname" struct tag matching the original YAML key. This is required for correct marshaling/unmarshaling with gopkg.in/yaml.v3.
Are nested YAML objects converted to nested structs?
Yes. Each nested mapping gets its own named struct type and the parent field uses it, so jobs.build.steps turns into Jobs, Build and []Step. Field names are exported Go identifiers (runs-on becomes RunsOn, userId becomes UserID), and the yaml tag keeps the original key.
Is my YAML data sent to a server?
No. All conversion happens in your browser using JavaScript. Your YAML never leaves your device.
Can I use the output directly with yaml.Unmarshal()?
Yes. The generated struct with yaml tags is ready for use with gopkg.in/yaml.v3's yaml.Unmarshal() function.
Related YAML Tools
Explore other YAML conversion tools: