JSON to Kotlin Data Class

Generate Kotlin data classes with @JsonProperty annotations from any JSON object.

What is a Kotlin Data Class?

A Kotlin data class is a special class that holds data. It automatically generates equals(), hashCode(), toString(), and copy() implementations, making it the idiomatic way to represent API response bodies, database models, and DTOs in Kotlin.

When consuming REST APIs in Android or Kotlin backend projects, you need data classes that match the JSON structure. Writing these by hand for complex JSON responses is tedious. This tool generates all the data classes from your JSON, including nested classes, proper type mappings, and @JsonProperty annotations for snake_case keys.

JSON to Kotlin Data Class Example

Input JSON:

json
{
  "id": 1,
  "first_name": "Alice",
  "is_active": true,
  "score": 9.5,
  "address": { "city": "Berlin", "zip": "10115" }
}

Generated Kotlin data classes:

kotlin
import com.fasterxml.jackson.annotation.JsonProperty

data class Address(
    val city: String,
    val zip: String
)

data class Root(
    val id: Long,
    @JsonProperty("first_name")
    val firstName: String,
    @JsonProperty("is_active")
    val isActive: Boolean,
    val score: Double,
    val address: Address
)

Gradle Dependency

kotlin
// build.gradle.kts
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.+")

Or use Spring Boot's built-in Jackson: no extra config needed.

Type Mapping

JSON TypeKotlin TypeNotes
stringStringNon-nullable
integerLongAll whole numbers
floatDoubleDecimal numbers
booleanBooleantrue / false
nullAny?Nullable Any
arrayList<T>T inferred from first element
objectdata classNew named data class

Frequently Asked Questions

Add the kotlin-module dependency. When using Spring Boot, annotate your Application class with @SpringBootApplication — it automatically registers the KotlinModule.

Keys are converted to camelCase and a @JsonProperty annotation is added to map back to the original JSON key name.

This generator targets Jackson annotations. For kotlinx.serialization, change @JsonProperty to @SerialName and use @Serializable on each class.

JSON null maps to Any?. If you know the underlying type, update it to YourType? after generation.

Yes — the generated data classes work with Retrofit + Gson or Jackson for Android API clients.

Related Tools