Kotlin data classes from a JSON sample
Paste a JSON document and get data class declarations ready for the serializer your project uses. Every object shape becomes a class with val properties, nested objects reference their own classes, and arrays become List<T>.
Example
With Serialization set to kotlinx.serialization:
package com.example.api
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
data class Customer (
val id: Long,
val name: String,
val tags: List<String>,
val orders: List<Order>
)
@Serializable
data class Order (
val sku: String,
val qty: Long,
val gift: Boolean? = null
)
gift is nullable with a default because only some orders in the sample carry it.
Choosing a framework
Jackson is the default and matches most server-side Kotlin. It emits a configured ObjectMapper and extension functions for parsing unless Types only is checked. kotlinx.serialization is the choice for multiplatform or Android projects already on the Kotlin compiler plugin. Klaxon is kept for older Android codebases that use it.
Package sets the package line. Acronyms controls how a key like httpURL is cased in the property name.
Limits
Kotlin has no union type, so a field that mixes types in the sample becomes a sealed class with one subclass per type and a custom serializer. A field that is always null becomes JsonElement? under kotlinx or Any? under Jackson. Repeated string values become an enum class when enum inference is on. ISO 8601 strings become OffsetDateTime when date inference is on, which pulls in java.time and so limits the output to the JVM; turn Dates from ISO strings off for multiplatform targets.