Skip to content
gohacks.dev
Tooling

JSON to Kotlin Data Class Generator

Generate Kotlin data classes from a JSON sample for kotlinx.serialization, Moshi or plain use, with camelCase properties and nullable defaults.

Free · No sign-up · Your inputs stay in your browser

Input

Generate Kotlin types from JSON

Output

Kotlin

540 characters

Keys become camelCase properties with @SerialName or @Json carrying the original name. Nullable or missing keys are typed T? with a null default, so decoding a payload without them does not throw. Types come from this one sample: give fields that are null here a real value to type them.

Runs in this browser. Nothing you paste is sent to a server.

Picking the library

kotlinx.serialization is the JetBrains library and works on every Kotlin target, including multiplatform; it needs the compiler plugin and @Serializable on each class. Moshi is common on Android and generates adapters with KSP when @JsonClass(generateAdapter = true) is present.

Defaults matter for decoding

kotlinx.serialization throws on a missing key unless the property has a default value, which is why nullable properties here default to null. Set Json { ignoreUnknownKeys = true } so fields added to the API later do not break older app versions.

Share

Frequently asked questions

Why does decoding fail with MissingFieldException?
A non-nullable property without a default is required. Make the property nullable with = null, or give it a default value, for keys the API may omit.
Can I use these classes with Retrofit?
Yes. Use the kotlinx.serialization or Moshi converter factory that matches the annotations you generated.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools