Advertisement

JSON to Kotlin Data Class

Turn JSON into Kotlin data classes with val properties. Nullable types, default values, List fields, and nested classes are inferred for you.

JSON input

Paste JSON, optionally name the root type, then generate.

Your Kotlin data class code will appear here.
Advertisement

Concise models for Android and backend

Kotlin data classes compress a whole JSON object into one line of properties. The generator infers String, Int, Double, Boolean, List, and nested data classes, marking unreliable fields nullable with sensible defaults.

Serialization ready

Whether you use kotlinx.serialization, Moshi, or Gson, the generated shape is what those libraries expect: a primary constructor with named properties and nullability that mirrors the real payload.

JSON to Kotlin Class FAQs

What is a Kotlin data class?
A data class is Kotlin's concise holder for data: the compiler generates equals, hashCode, toString, and copy from the constructor properties you declare.
How are optional fields expressed?
Uncertain fields become nullable types with a default of null, like nickname: String? = null, so missing JSON keys deserialize without errors.
Does the output work with kotlinx.serialization?
Yes. Add @Serializable to the classes and the plugin handles the rest. The nullable defaults align perfectly with missing keys.
How are arrays typed?
JSON arrays become List<T> with T inferred from the elements, which is the standard Kotlin collection for deserialized lists.
Why data classes and not regular classes?
Data classes give you structural equality and copy() for free, which is exactly what you want for API models that get compared and transformed.
Advertisement