ToolLineup

YAML to Code Generator

Paste a YAML document and pick a target language: TypeScript, JavaScript, Python, Go, Java, C#, Kotlin, Rust, Dart, Objective-C or JSON Schema. YAML is typed, so strings, numbers, booleans and nulls survive intact and the declarations are as precise as they would be from the equivalent JSON. Anchors and aliases are expanded before the shape is inferred. Useful for giving a config file or a deployment manifest a real type.

How it works

Paste a representative YAML sample and the chosen language’s declarations appear on the right. The types are inferred from what is actually in the sample, so the more complete your example, the better the result — one array element with an extra field is enough to have that field marked optional rather than missed.

YAML is typed, so strings, numbers, booleans and nulls survive the conversion intact and the generated declarations are as precise as they would be from the equivalent JSON. Anchors and aliases are expanded before the shape is inferred.

Every object in the sample becomes an exported interface, named after the key that held it. Arrays become typed arrays, and an array of objects contributes one interface for its items rather than one per element.

A field missing from some records in an array is marked optional with a question mark, and a field that was null somewhere is unioned with null — so the types describe what the data can actually be, not just what the first record happened to contain.

Generation runs entirely in your browser — nothing you paste is uploaded.

YAML sample
Paste a representative YAML document…
TypeScript interfaces

Frequently asked questions

Are YAML types preserved as accurately as JSON types?

Yes. Unlike XML, YAML distinguishes strings, numbers, booleans and nulls, so the inferred declarations are exactly as precise as they would be from the equivalent JSON document.

What happens to anchors and aliases?

They are expanded before the shape is inferred, so a block reused through an alias contributes its full structure to the type rather than appearing as an unresolved reference.

Can I use this to type a config file?

That is the main reason to reach for it. Pasting a representative config or deployment manifest gives you a declaration you can validate against at load time, which turns a typo in a YAML key into an error at startup rather than a mystery at runtime.

How are fields that vary between list items handled?

The shapes of all items in a sequence are merged into one type, and any field missing from some of them is marked optional — so an example with one entry that has an extra key is enough to get that key represented correctly.

What if my YAML has multiple documents?

Only the first document is read. Split a multi-document file and generate from each part separately, since they usually describe different things and would merge into a misleading union otherwise.

Related tools