Skip to content
100% local

JSON to Kotlin data class

Turn a JSON sample into a ready-to-use Kotlin data class.

Input
Output

JSON to Kotlin data class

Paste a JSON response and this tool converts it into a ready-to-use Kotlin data class, inferring every field's type directly from the values you provide. It's built for Android and backend developers who need a quick model for an API response, a config file or a sample payload, without hand-typing property names and types or reaching for an IDE plugin.

Set a name for the root class, and choose how nested objects appear: nested inside the root class or declared as separate top-level classes. Switch between val for immutable properties and var when the model needs to be mutable, and turn on default values to give every property a sensible fallback (an empty string, zero, emptyList()) so instances can be created with fewer arguments. Add @Serializable and @SerialName annotations for kotlinx.serialization, or @SerializedName for Gson, and pick 2-space, 4-space or tab indentation to match your project's style.

Missing or null values become nullable types automatically, arrays become List<T> with the element type inferred from every item, and objects with the same shape are collapsed into one reused class instead of being duplicated. The "merge fields across array elements" option controls whether that item type is built from every element in the array or just the first one, which is useful for a very large or unevenly shaped array. When the JSON at the top level is itself an array, the tool wraps the inferred item type in a List for you.

Everything runs locally in your browser — your JSON is never uploaded or sent to a server, so it's safe to paste real API responses and internal payloads. Copy the generated Kotlin, download it as a .txt file, or send the output back into the input to convert it again with different options.

FAQ

How does the tool decide which fields are nullable?
A field becomes nullable when it's missing from at least one sample object, or when its only observed value is null. A field present with a non-null value in every object stays non-nullable.
Can it generate the kotlinx.serialization or Gson annotations I need?
Yes. Choose kotlinx.serialization to add @Serializable and @SerialName, or Gson to add @SerializedName with the original JSON key, so the class deserializes correctly even when the property name differs.
What happens with a JSON array whose objects have different shapes?
Their fields are merged into one data class, with any field missing from some elements marked nullable. Turn off "Merge fields across array elements" to infer the type from only the first element instead.
Does it support nested objects?
Yes. A nested object becomes its own data class, either declared inside the root class or as a separate top-level class, depending on the nesting option.
Is my JSON uploaded anywhere?
No. The conversion runs entirely in your browser — your JSON never leaves your device.