CalcCafe

YAML to Kotlin

Paste any YAML document and generate ready-to-use Kotlin data classes with inferred types and nested structures.

Example

Input YAML:

name: Acme
version: 3
owner:
 id: 1001
 email: [email protected]
tags:
 - mobile
 - kotlin

Generated Kotlin:

data class Owner(
  val id: Int,
  val email: String
)

data class Root(
  val name: String,
  val version: Int,
  val owner: Owner,
  val tags: List<String>
)

How it works

The tool parses your YAML with js-yaml, walks the resulting value to infer Kotlin types (Int, Long, Double, Boolean, String, List, nested classes), and emits data class definitions starting from a root type named Root. Everything runs locally in your browser.

Good to know

YAML to Kotlin turns a pasted YAML document into a set of Kotlin data class definitions, inferring each field's type from the actual values you provide. It's aimed at Android and Kotlin/JVM developers who receive configuration files, API responses, or fixtures in YAML and want a typed model to deserialize into instead of hand-writing classes field by field. Paste your YAML, hit Convert, and you get a Root class plus a separate class for every nested mapping.

Reach for it when you're wiring up a YAML config (CI files, app settings, Helm-style values) or sketching a model before pulling data through a parser like Jackson or kotlinx.serialization. It saves the tedious part of mapping keys to properties and naming intermediate types, and because it runs entirely in your browser, you can safely paste internal or sensitive config without it leaving your machine.

To read the output: the order matters because nested classes are emitted before the parent that uses them, and the entry point is always Root. Type inference follows your data, so a value like 4.5 becomes Double, a whole number becomes Int (or Long if it exceeds the 32-bit range), and true/false becomes Boolean. Keys with non-identifier characters are converted to camelCase property names, and class names are derived in PascalCase from the key, with numeric suffixes added if two different shapes would collide.

A practical caveat: inference reflects only the sample you paste, so a field that happens to be a whole number in your example becomes Int even if the real schema allows decimals. Empty values, nulls, and mixed-type lists fall back to Any?, and the generated classes have no serialization annotations. Treat the result as a fast first draft, then adjust nullability and add the annotations your parser needs.

Frequently asked questions

How are nested YAML objects handled?
Each nested mapping becomes its own Kotlin data class named after its key in PascalCase, and the parent references it by type. The top-level type is always called Root.
How does it decide between Int, Long, and Double?
Whole numbers within the 32-bit range become Int, larger whole numbers become Long, and any number with a decimal becomes Double. When a list mixes numeric kinds, the widest compatible type is chosen.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

Does the generated Kotlin include @Serializable or Jackson annotations?
No. It emits plain data classes with typed properties and no serialization annotations. You add @Serializable (kotlinx.serialization) or Jackson/Moshi annotations yourself afterward based on the library you use.
How does the tool handle null or missing YAML values?
Values that are null or empty are typed as Any?. When a key is present in some items of a list of objects but missing in others, that field is marked nullable with a trailing question mark.
Why does my field show up as Any? instead of a concrete type?
That happens when a value is null, a list is empty, or a list mixes incompatible types (for example strings and objects) so no single Kotlin type fits. Provide a more representative sample to get a concrete type.
Can it convert a YAML file whose top level is a list instead of a map?
Yes. A top-level sequence produces a Root class with a single items property typed as List of the inferred element type, and a separate class is generated for the element shape when the items are objects.
What does it name the classes and properties?
The top-level class is always Root, and each nested mapping becomes a class named in PascalCase after its key. Property names are converted to camelCase, and identifiers that would start with a digit are prefixed with an underscore.
Does it deduplicate identical nested structures into one class?
Yes. Objects with the same set of keys and types are reused as a single class. When two different shapes would otherwise share a name, a numeric suffix is appended to keep the names unique.
Will the Kotlin output compile as-is?
The class definitions are syntactically valid Kotlin, but you may need to adjust nullability, rename collided types, or add annotations and imports for your deserialization library before it fits your project.

Related tools