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.

1

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
    - backend
2

Click Convert

Click the Convert button. The right panel shows Go struct code with PascalCase field names and yaml struct tags for each field.

3

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, integer → int, float → float64, boolean → bool, list → []interface{}, mapping → nested struct, null → 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. Nested YAML mappings become nested Go structs with their own field definitions.

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: