Class name:
JSON Input 0 B
Ready
0 chars
Kotlin Output 0 B
Kotlin data classes will appear here...
0 chars
Features

Why use this generator

SerializedName

Every field gets a @SerializedName("name") annotation for Gson compatibility. The Kotlin property name follows camelCase convention.

Type mapping

JSON strings become String, integers become Long, floats become Double, booleans become Boolean, null becomes Any?. Arrays become List<T>.

Data classes

Uses Kotlin's data class for concise immutable models. Each nested object becomes its own data class with a derived name.

How it works

Conversion explained

1. Parse JSON

Input is parsed into a JavaScript value. The class structure is determined by walking the value tree.

2. Collect classes

For each object, a Kotlin data class is generated with constructor properties and SerializedName annotations.

3. Emit Kotlin

Classes are emitted with proper Kotlin formatting: data class keyword, constructor properties, and proper indentation.

FAQ

JSON to Kotlin Data Class Generator — frequently asked questions

Which JSON libraries are compatible?

The output uses @SerializedName from Gson. For Moshi, replace with @Json. For kotlinx.serialization, replace with @SerialName and add @Serializable.

Why use Long instead of Int?

JSON integers can be very large (JavaScript numbers go up to 2^53). Long (64-bit) handles all possible JSON integers safely.

Are nullable types supported?

Currently, nullable fields use Any?. For proper nullable typing, edit the output to use specific nullable types like String?, Long?.

Can I use this for Android development?

Yes — the output is directly compatible with Android projects using Gson or Moshi. For Retrofit, the generated data classes work as response models.