YAML to Go Converter

Convert YAML to Go struct with yaml tags

YAML Input

Go Output

Paste your YAML on the left and the Go code shows up here.

Or drop a file on this box, , or .

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.

1

Paste or Upload Your YAML

Drop a config file into the left pane or open one with Upload (.yaml, .yml or .txt). Sample fills in a billing-api config with separate app and database blocks. The smaller service block below works as well:

service:
  name: my-api
  port: 8080
  replicas: 3
  debug: false
  tags:
    - api
    - backend
2

Click Convert

Nothing to click here. A beat after your last keystroke the right pane rewrites itself: the service block above becomes a Root struct holding a Service field, and Service gets Name string, Port int, Replicas int, Debug bool and Tags []string, each tagged with its original key, as in yaml:"replicas".

3

Copy or Download the Go Code

Copy sends the code to the clipboard and Download saves converted.go. The file starts with package main, so change that to your own package, run gofmt to line the tags up, then pass a pointer to a Root value into yaml.Unmarshal from gopkg.in/yaml.v3.

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.

Does my config leave the browser while it turns into Go structs?

No. The input is parsed in the page and the struct text is put together by a few TypeScript functions in the same tab, so a database host or internal port in your config is never transmitted.

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: