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:
{
"id": 1,
"first_name": "Alice",
"is_active": true,
"score": 9.5,
"address": { "city": "Berlin", "zip": "10115" }
}Generated Kotlin data classes:
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
// 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 Type | Kotlin Type | Notes |
|---|---|---|
| string | String | Non-nullable |
| integer | Long | All whole numbers |
| float | Double | Decimal numbers |
| boolean | Boolean | true / false |
| null | Any? | Nullable Any |
| array | List<T> | T inferred from first element |
| object | data class | New named data class |