YAML to Go screenshot

YAML to Go

Turn a YAML sample into go structs: one type per mapping, nested types named from their field, arrays typed from their first item.

Privacy First
0 Runs
Updated 2026-11-17
Runs in your browser
No sign-up, no upload

What the YAML to Go does

The YAML is parsed by the shipped js-yaml build, then the value is walked once into a shape: a mapping with named properties, a list with one item shape, or a scalar. Every type declaration is generated from that shape, so a nested object cannot be flattened by accident.

An integer sample becomes an integer type and a fractional one becomes a float, because the sample is the only evidence the page has about the field's type.

The sample is the whole contract: a value that is null in the sample has no type, so it becomes the language's widest type (interface{}, Option<serde_json::Value>, unknown | null, Optional[Any]). A list is typed from its first item only, so a mixed list is typed wrongly.

How to use it

Paste the YAML into the YAML sample box, or press Run with the example already there.

Read the go structs below: the root mapping is the last type, and every nested mapping appears before it.

Check a nested field in the Go structs — its type name comes from the field, so address becomes Address in every language.

Worked example

Input:

user:
  name: Ada
  age: 36
  address:
    city: London
  tags:
    - a
    - b

Output:

type Address struct {
	City string `yaml:"city"`
}

type User struct {
	Name string `yaml:"name"`
	Age int `yaml:"age"`
	Address Address `yaml:"address"`
	Tags []string `yaml:"tags"`
}

type Root struct {
	User User `yaml:"user"`
}

Why it runs in your browser

The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.

A shape read from the document you paste, printed as go structs with `yaml:\"key\"` tags.

The root mapping becomes `Root`, a nested `address` mapping becomes `Address`, and a list of mappings becomes `<Field>Item`, so no type borrows the name of the list that holds it.

What it does, and what it does not

The YAML is parsed by the shipped `js-yaml` build, then the value is walked once into a shape: a mapping with named properties, a list with one item shape, or a scalar. Every type declaration is generated from that shape, so a nested object cannot be flattened by accident.

An integer sample becomes an integer type and a fractional one becomes a float, because the sample is the only evidence the page has about the field's type.

The sample is the whole contract: a value that is null in the sample has no type, so it becomes the language's widest type (`interface{}`, `Option<serde_json::Value>`, `unknown | null`, `Optional[Any]`). A list is typed from its first item only, so a mixed list is typed wrongly.

How to use YAML to Go

Paste the YAML into the YAML sample box, or press Run with the example already there.

Read the go structs below: the root mapping is the last type, and every nested mapping appears before it.

Check a nested field in the Go structs — its type name comes from the field, so `address` becomes `Address` in every language.

What to Expect

Best for

  • Starting Go types from a real config file
  • Seeing how a YAML shape maps to Go

Not ideal for

  • Typing a mixed list, which is typed from its first item
  • Recovering a comment or an anchor the parser resolved

What this tool keeps

  • One type per mapping, named from its field
  • Integer and float samples kept distinct

What may need cleanup

  • A null sample needs a type chosen by hand
  • A mixed list needs a hand-written union

Common errors

  • The page refuses it: the YAML root must be a mapping, not a sequence

Example use cases

  • Typing a config file in Go
  • Checking a nested shape before writing the structs

Sample input

YAML sample: user: …

Sample output

Go structs: type Address struct { …

Who this is for

  • Go developers reading a YAML config
  • Anyone porting a config into typed code

Frequently asked questions

How are nested types named?

From the field that holds them: address becomes Address, and a list of mappings under people becomes PeopleItem, so the list and its element never share a name.

What happens to a null value?

It has no type in the sample, so the page emits the widest one it has rather than guessing. Narrow it by hand where you know what the field holds.

Does it read YAML anchors and aliases?

The shipped parser resolves them, so the shape you get is the expanded document. A recursive alias is refused by the parser rather than looped forever.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.