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 @Serializable classes ready to decode.
  • KMP projects — share generated models across platforms.
  • Map odd keys — get @SerialName where a key is not a valid identifier.
  • Switch libraries — keep the data classes and swap to Moshi or Gson.

Frequently asked questions

Which serialization library does it target?

kotlinx.serialization, generating @Serializable data classes.

How are non-identifier keys handled?

A key that is not a valid Kotlin name gets a @SerialName annotation mapping it to a clean property.

Can I use Moshi or Gson?

Yes — keep the data class structure and replace the annotations to suit the library.

Is this good for Android and KMP?

Yes — the output suits Android apps and Kotlin Multiplatform projects.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: