YAML to Go
Processed Client SideGenerate idiomatic Go structs with tags from a YAML document, with nested types inferred.
Bookmark this tool now — skip the search next time you need it.
About YAML to Go
This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.
The YAML to Go converter turns a YAML document into idiomatic Go structs, ready to paste into a package and unmarshal into. It infers the type of every field from the sample values, gives nested maps their own named structs, merges the shapes of objects inside a list so entries with slightly different keys still produce one type, and applies Go naming conventions including the initialisms the style guide insists on, so user_id becomes UserID rather than UserId. Choose yaml tags, json tags, or both, name the root struct, and copy the result. Parsing and code generation both happen in your browser, so configuration files that often hold secrets never leave your machine.
Key features
- Idiomatic Go structs generated from any YAML document
- yaml tags, json tags, or both emitted on every field
- Nested maps become their own named structs and are referenced as pointers, so a missing section unmarshals as nil
- Objects inside a list are merged into one struct, so entries with extra keys still fit a single type
- Go naming with initialism handling: api_url becomes APIURL, http_ttl becomes HTTPTTL
- Types inferred from the values, including slices and interface{} where a key is mixed or always null
- Configurable root struct name, with collisions resolved automatically
- Field and type columns aligned the way gofmt would align them
- Highlighted YAML in and highlighted Go out, running entirely in your browser
How to use it
- Paste a YAML document into the left pane.
- Type the name you want for the top-level struct.
- Choose whether to emit yaml tags, json tags, or both.
- Click Convert to generate the structs.
- Copy the Go into your package and unmarshal into it.
Tips & common mistakes
- Give the richest sample you have. Fields absent from the sample cannot be generated, and a key that is null everywhere can only become interface{}.
- Whole numbers become int and anything with a decimal point becomes float64, so write 1.0 rather than 1 where the field really is a float.
- A key whose values have different types across the sample resolves to interface{}. Splitting it into two fields is almost always the better fix.
- Pick yaml plus json tags when the same struct serves both a config file and a JSON API.
- Struct names are a starting point, not a decision. Rename them to fit your domain freely; the tags carry the wire format, so the YAML keeps matching.
- Add omitempty by hand where you need it. The generator emits plain tags so nothing is silently dropped on marshal.
- Only one document is read at a time. If your file uses --- separators, convert each document on its own.