Skip to content
AZ Tools

JSON to Kotlin Data Class Converter

Turn a JSON object into Kotlin data classes with typed properties, in your browser.

Kotlin data classes

How to use

  1. Paste or type your JSON into the input box.
  2. Optionally rename the root class (defaults to AutoGenerated).
  3. Copy the generated data classes from the output box.
  4. Add a question mark to any property your API may omit — one sample cannot show which fields are optional.

About this tool

Show

Paste any JSON object or array and get ready-to-use Kotlin data class definitions with typed val properties and separate classes for nested objects, each named after the key that held it. Whole numbers become Long and fractional ones Double, a deliberately wide default that keeps large IDs and timestamps from overflowing Int. A JSON null becomes Any?, since a single sample cannot say what type belongs there, and an empty array becomes List<Any>. Because the shape is inferred from one document, nullability is the part to review by hand: a field that merely happens to be present in your sample is generated as non-null, so add a question mark wherever the API can omit it. Everything runs locally in your browser — your JSON is never uploaded.

Frequently asked questions

How are numbers typed?

Whole numbers become Long and numbers with a decimal point become Double. Change to Int or Float manually if you prefer a narrower type.

What happens with null or empty arrays?

null values map to a nullable Any? and empty arrays to List<Any>, since their type can't be inferred from the sample.

How are nested objects handled?

Each nested object becomes its own data class. An empty object becomes a plain class, since a data class needs at least one property.

Is my JSON sent anywhere?

No. Conversion happens entirely in your browser; nothing is uploaded.

Which field should I make nullable?

Any the API can omit or send as null — the sample cannot tell you which those are. Adding a question mark also lets you give the property a default, so an older client keeps working when the server starts leaving a field out.

Do these data classes work with kotlinx.serialization?

Add the @Serializable annotation and the plugin, and they will. If a JSON key is not a valid Kotlin name or you prefer camelCase properties over the wire spelling, annotate the property with @SerialName rather than renaming it and breaking the mapping.

Related tools