How to convert JSON to Kotlin
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated Kotlin code into your project.
What you get
@Serializabledata classes for kotlinx.serialization.- camelCase properties with
@SerialNamewhen the JSON key differs. - Nullable types with
= nulldefaults for optional fields, andJsonElementfor mixed data.
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
How do I parse the JSON?
Apply the kotlinx.serialization plugin, then call Json.decodeFromString<Root>(text). Use Json { ignoreUnknownKeys = true } if the API may add fields.
Does it work with Moshi or Gson?
The classes are plain Kotlin. Replace @SerialName with @Json(name = …) for Moshi or @SerializedName for Gson, and remove @Serializable.
Why Long and Double?
Whole numbers become Long so large IDs fit, and numbers with decimals become Double. Change them to Int or Float if you prefer.