JSON to Kotlin Data Class
Generate Kotlin @Serializable data classes (kotlinx.serialization) from JSON. Useful for Android apps and KMP projects. Nested objects become nested data classes; non-Kotlin-valid keys get @SerialName annotations.
How to use the JSON to Kotlin Data Class
Paste JSON. Output uses kotlinx.serialization. For Moshi or Gson, swap the annotations — the data class structure is the same.
Generating Kotlin data classes from JSON
Kotlin data classes are a natural fit for JSON: declare the properties and you get equality, copying, and a readable structure for free. The remaining chore is wiring them to the JSON — the right types, the @Serializable annotation, and a @SerialName wherever a key is not a valid Kotlin identifier.
This generates Kotlin @Serializable data classes for kotlinx.serialization from a JSON sample, nesting a data class per nested object and adding @SerialName for keys that need it — handy for Android and Kotlin Multiplatform projects. For Moshi or Gson you can keep the data classes and swap the annotations. On the JVM the Java generator is the more verbose counterpart.
Common use cases
- Android models — generate data classes for an app’s API layer.
- kotlinx.serialization — get
@Serializableclasses ready to decode. - KMP projects — share generated models across platforms.
- Map odd keys — get
@SerialNamewhere a key is not a valid identifier. - Switch libraries — keep the data classes and swap to Moshi or Gson.