Paste an API response or a config JSON and get Kotlin data class code that mirrors its structure. Nested objects and arrays of objects each become their own class, and you can target either kotlinx.serialization or Jackson.
It is built for the moment you wire up an external API in an Android app or a Ktor/Spring service and want the model skeleton from one sample response instead of typing it out. Conversion runs entirely in your browser, so pasting an internal API response does not send it anywhere.
Type name to the top-level class name (default Root), for example UserResponse.Serializer, matching what your project already uses.{
"orderId": "A-1024",
"paid": true,
"total": 39.9,
"coupon": null,
"items": [
{ "sku": "TSHIRT-M", "qty": 2 },
{ "sku": "CAP", "qty": 1, "gift_wrap": true }
]
}import kotlinx.serialization.Serializable
import kotlinx.serialization.SerialName
import kotlinx.serialization.json.JsonElement
@Serializable
data class Order(
val orderId: String,
val paid: Boolean,
val total: Double,
val coupon: JsonElement? = null,
val items: List<Item>
)
@Serializable
data class Item(
val sku: String,
val qty: Int,
@SerialName("gift_wrap") val giftWrap: Boolean? = null
)
Objects inside the items array become a singular Item class, and gift_wrap, which appears only in the second item, becomes Boolean? = null. coupon is only ever null, so its type can't be inferred and it is left as JsonElement? for you to replace with the real type.
@Serializable on every class, @SerialName on fields whose name changed, plus the required imports.@JsonProperty only on fields whose name changed.user_name or home-url become camelCase properties (userName, homeUrl) mapped back to the original key by annotation.class or val are wrapped in backticks; keys starting with a digit get an n prefix.Int, values beyond 32-bit become Long, and any decimal makes the field Double.? = null.typealias, e.g. typealias Root = List<RootItem>.Paste a response copied from Postman or browser DevTools and you get classes ready for Call<Order> or client.get<Order>(). With responses that have dozens of fields, this avoids typos and wrong types from copying by hand.
When the backend sends created_at, the Kotlin side reads createdAt while the serial name keeps the original key. The mapping stays visible per class instead of relying on a global naming strategy.
If you are moving Gson or Jackson models to kotlinx.serialization, generate both outputs from the same JSON to see exactly which annotations change.
? yourself for fields the API docs say can be omitted.2024-01-01T00:00:00Z stay String; switching to Instant requires your own serializer.Any, so values with no inferable type become JsonElement there and Any with Jackson.String? = null rather than just String??kotlinx.serialization throws MissingFieldException when a key is absent and the property has no default. Adding = null to fields that are missing in some items or contain null lets responses without that key decode cleanly.
@SerialName?The tool always converts to camelCase and adds an annotation only when the name differs, so keys that are already camelCase come out without annotations. To keep snake_case names, rename the properties and drop the annotations after generating.
Yes. The generated data class has no no-arg constructor, so Jackson needs jackson-module-kotlin registered to bind values through constructor parameters (Spring Boot registers it automatically when the dependency is present).
The serializer options are kotlinx.serialization and Jackson. For Gson, take the Jackson output and replace @JsonProperty with @SerializedName; for Moshi, use @Json(name = ...). The class structure stays the same.