Convert JSON to Kotlin data class!

Input JSON to generate Kotlin data class code, including nested objects! Supports kotlinx.serialization @Serializable/@SerialName and Jackson.
JSON
Result
 

Convert JSON to Kotlin data class!

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.

How to use

  1. Paste JSON into the input box. A complete real response gives better type inference than a trimmed one.
  2. Set Type name to the top-level class name (default Root), for example UserResponse.
  3. Pick kotlinx.serialization or Jackson under Serializer, matching what your project already uses.
  4. Copy the generated code into your model file. The type name and serializer are kept in the URL, so a bookmark reopens the same setup.

Example

Input (JSON)
{
  "orderId": "A-1024",
  "paid": true,
  "total": 39.9,
  "coupon": null,
  "items": [
    { "sku": "TSHIRT-M", "qty": 2 },
    { "sku": "CAP", "qty": 1, "gift_wrap": true }
  ]
}
Output (Kotlin · kotlinx.serialization)
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.

Supported features

  • kotlinx.serialization: @Serializable on every class, @SerialName on fields whose name changed, plus the required imports.
  • Jackson: @JsonProperty only on fields whose name changed.
  • Keys like user_name or home-url become camelCase properties (userName, homeUrl) mapped back to the original key by annotation.
  • Kotlin keywords such as class or val are wrapped in backticks; keys starting with a digit get an n prefix.
  • Numbers: integers become Int, values beyond 32-bit become Long, and any decimal makes the field Double.
  • Arrays of objects are merged into one class from all items; fields present in only some items become ? = null.
  • A top-level array or primitive produces a typealias, e.g. typealias Root = List<RootItem>.

Use cases

Response models for Retrofit or Ktor clients

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.

Mapping a snake_case API to Kotlin naming

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.

Migrating to kotlinx.serialization

If you are moving Gson or Jackson models to kotlinx.serialization, generate both outputs from the same JSON to see exactly which annotations change.

Notes and limitations

  • Types are inferred only from the sample you paste. A field present in every sample item comes out non-null, so add ? yourself for fields the API docs say can be omitted.
  • Date strings like 2024-01-01T00:00:00Z stay String; switching to Instant requires your own serializer.
  • kotlinx.serialization cannot serialize Any, so values with no inferable type become JsonElement there and Any with Jackson.
  • No enums, sealed classes or default values (like empty lists) are generated. Fields with a fixed set of values are worth turning into enums afterwards.
  • All classes come out in one block; package declarations and splitting into files are up to you.

FAQ

Why is a field 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.

Can I keep JSON keys as property names without @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.

Do I need jackson-module-kotlin when choosing Jackson?

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).

Can it generate Moshi or Gson models?

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.