YAML to Go Struct Generator
CV-89Paste a YAML document and press Convert to get structs with json tags. The YAML is read into JSON first, so the types come from its values, and it runs in your browser.
Runs in your browser. Nothing is uploaded.
YAML
Go
How to use it
- Paste one YAML document, or open a .yaml or .yml file. Use a sample that shows every section you expect.
- Choose Go initialisms, pointers for missing keys and whether every field gets omitempty.
- Press Convert, then copy the result or download it as a .go file.
- Unmarshal into the first struct with json.Unmarshal(data, &root). The names follow the JSON form of your YAML, so add the tags your YAML library needs if you load YAML directly.
How the structs are built
Each object becomes a struct with exported CamelCase field names and a json tag holding the original key. Common initialisms such as ID, URL and HTTP are written in capitals, which you can switch off. Mixed types, empty arrays and keys that are always null become interface{}, and a key with a comma or backtick in it raises an error because a struct tag cannot hold it. Whole numbers become int, or int64 beyond the 32-bit range, and decimals become float64.
How the YAML becomes structs
Anchors, aliases and << merge keys are resolved, so the values they point to appear in the generated types. Comments are dropped, only one document is read, and keys that are not text become text. A value written as 1.0 is read as the number 1, and an integer beyond 9007199254740991 is rounded by the YAML reader. .nan and .inf become null. Keys that are not valid Go names, such as first-name, are renamed, and the original key is kept in the json struct tag.
What a sample cannot tell it
The result only reflects the sample you paste: a key that never appears has no member, and a number that is always whole in the sample is typed as whole even if other data holds decimals. Dates stay string; change them to time.Time by hand, and check pointer fields against what your data can really contain. A YAML file with optional sections should be pasted with every section present, or the missing sections will not appear in the output.
Questions people ask
How do I convert YAML to a Go struct?
Paste the YAML into the input box, choose your options and press Convert to get the structs. Unmarshal into the first struct with json.Unmarshal(data, &root). The structs follow the JSON form of the YAML. The conversion happens in your browser.
Why does the Go converter complain about a comma or backtick?
A Go struct tag is written between backticks and splits its options at commas, so a key containing either character cannot be stored in the json tag. The error names the key; rename it in the sample, then convert again. This applies to the JSON form of your YAML.
Why is a Go field typed interface{}?
Mixed types in one key, a key that is always null, and an empty array all give interface{}, because the sample does not show one clear type. Replace it with the type you expect, or paste a sample where the key has a value. This applies to the JSON form of your YAML.
Why do some Go fields become pointers?
A key that is null in some items, or missing from some objects, becomes a pointer so Go can tell absent from zero. A key missing from some objects also gets omitempty in its tag. You can turn the pointers off, or add omitempty to every field. This applies to the JSON form of your YAML.
Can I paste a YAML file with several documents?
No. Only a single document is read; a file with --- separators between documents gives an error. Paste one document at a time, or merge them into a list under one top-level key yourself. The Go structs are written from that converted data.
Are YAML dates and timestamps typed as dates?
No. The core schema is used, so 2026-01-05 stays a string and the generated field is a string type. Change it to a date type by hand if your language has one. The Go structs are written from that converted data.
About this tool
The YAML is read with the core schema (true/false, null, integers and floats), converted to JSON, and the code is generated from that. Dates stay text, comments are dropped, anchors, aliases and << merge keys are resolved, keys that are not text become text, and only one document is read. A value such as 1.0 is read as the number 1, so a field that holds whole-looking decimals can come out as an integer type; an integer beyond 9007199254740991 is rounded by the YAML reader before any code is written; .nan and .inf become null. Every object becomes a struct with exported CamelCase fields and a json tag that keeps the original key. Whole numbers become int, or int64 beyond 32 bits; decimals become float64, and an integer beyond int64 also becomes float64 and can round. A key that is null in some items becomes a pointer and a key missing from some objects gets omitempty. Mixed types, always-null keys and empty arrays become interface{}. Keys that contain a comma or a backtick cannot go in a tag and raise an error. Everything runs in your browser; nothing is uploaded.