JSON to Kotlin Data Class
JSON to Kotlin Data Class Generator
Paste a JSON object and get Kotlin data class definitions with typed fields, nullable markers, and nested class generation. Handles strings, integers, doubles, booleans, lists, and nested objects. Works with Gson, Moshi, and kotlinx.serialization. Runs entirely in your browser.
Where Is This Useful?
@Serializable for kotlinx.serialization support in your shared module.How to Use
- Paste a JSON object in the input panel
- Set the root class name (defaults to Root)
- Click Generate Data Class or press Ctrl+Enter
- Copy the output or download as a
.ktfile - Add
@Serializable,@SerializedName, or@JsonClassannotations as needed
Type Mapping
- JSON string →
String - JSON integer →
Int - JSON float →
Double - JSON boolean →
Boolean - JSON null →
Any? - JSON object → named
data class - JSON array →
List<T>with inferred element type
Frequently Asked Questions
Does this add @SerializedName or @Json annotations?
No. The generated code uses plain data class without annotations. If your JSON key names differ from Kotlin field names, add @SerializedName (Gson) or @JsonProperty (Jackson) manually.
Is this compatible with kotlinx.serialization?
Yes. The data classes work with kotlinx.serialization, Gson, Moshi, and Jackson. For kotlinx.serialization, add the @Serializable annotation to each class.
How are nullable fields marked?
Fields whose JSON value is null are typed as Any?. Non-null fields use non-nullable types. For fields that may sometimes be null in a real API, adjust the type to nullable manually.
How is this different from JSON to TypeScript?
JSON to TypeScript generates TypeScript interfaces for web frontends. Kotlin data classes are for Android, backend, or KMP projects where the type system is statically compiled.
Is my JSON uploaded anywhere?
No. Everything runs locally in your browser. Your data never leaves your machine.
Related Tools