TXT · Text & Data tools

JSON to Kotlin Data Class Converter

Top-level type
Serialization
Acronyms
Package
JSON input
Kotlin output
Inference
KotlinlanguageJSON sampleinput0types0lines out0chars out
Go to the full JSON to Types generator with all ten languages

Shareable link

Settings are written to the URL as you change them. Nothing differs from the defaults yet.

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.

Frequently Asked Questions

Jackson with the Kotlin module, kotlinx.serialization, and Klaxon. The Serialization select changes the annotations and the parsing helpers; the data classes themselves stay the same.

Each data class gets @Serializable, and a leading comment shows how to parse with Json and the class's serializer(). Property names that differ from the JSON key get @SerialName.

A key missing from some objects becomes a nullable type with a default of null, such as val gift: Boolean? = null, so decoding succeeds whether the key is absent or null.

Whole numbers become Long and fractions become Double. Null-only fields become JsonElement? under kotlinx or Any? under Jackson, and ISO 8601 strings become OffsetDateTime when date inference is on.

Yes. Types only emits the data classes without the parsing comment or the Jackson mapper setup.

Generate types for one language

Full JSON to Types Generator tool

Explore Our Tools

Browse all tools