JSON to Kotlin Data Class
Generate Kotlin data classes from JSON instantly. Handles nested objects, arrays, nullable fields, and custom root class names. Free, runs in your browser.
How to Use
- Paste or type your JSON into the left panel. The tool validates it in real time.
- Optionally set a Root class name (default:
RootObject). - Click Generate Kotlin or wait for real-time conversion.
- Click Copy to copy the output to your clipboard.
Type Mapping
null→Any?- string →
String - integer number →
Int - floating-point number →
Double - boolean →
Boolean - array →
List<T> - nested object → separate
data class
Example
Given this JSON:
{"user": {"name": "Alice", "age": 30}, "tags": ["admin"]}
The tool generates:
@Serializable
data class User(
val name: String = "",
val age: Int = 0
)
@Serializable
data class RootObject(
val user: User = User(),
val tags: List<String> = emptyList()
) FAQ
What does this tool generate?
It generates Kotlin data class declarations annotated with @Serializable (kotlinx.serialization). Each nested object becomes its own named data class.
How are nullable fields handled?
If a JSON field's value is null, the corresponding Kotlin type is marked nullable (e.g. String?). Fields missing from some array items are also marked nullable and use null as the default.
What are the default values for each type?
String defaults to empty string "", Int to 0, Double to 0.0, Boolean to false, List to emptyList(), nullable types to null, and nested data classes call their zero-arg constructor.
Why are @SerialName annotations added?
When a JSON key cannot be represented as a valid Kotlin identifier (e.g. contains hyphens or spaces), or when camelCase conversion changes the name, @SerialName preserves the original JSON key name.
Is my data sent to a server?
No. The entire conversion runs in your browser. No data leaves your machine.