JSON to Kotlin Data Classes
Generate Kotlin data classes from JSON. Support for @Serializable annotation and nested class generation.
JSON Input
Kotlin Data Classes
About JSON to Kotlin Data Classes Generator
Kotlin data classes are the standard way to model JSON data in Android, Kotlin Multiplatform (KMP), and server-side Kotlin applications. Our JSON to Kotlin converter analyzes your JSON data and generates data classes with proper types (String, Int, Long, Double, Boolean, List<T>), nested class definitions, nullable types (String?), and optional @Serializable annotations for kotlinx.serialization. Whether you are building an Android app with Retrofit, a KMP library with Ktor, or a Spring Boot backend, this tool saves you from manually writing data class boilerplate.
How to Use JSON to Kotlin Data Classes Generator
Paste Your JSON
Paste a JSON object or array into the input editor. The tool examines each value to determine the correct Kotlin type: String, Int, Long, Double, Boolean, List<T>, or a nested data class.
Configure Options
Choose whether to include @Serializable annotations for kotlinx.serialization. Set the root class name to match your project naming conventions.
Copy or Download
Review the generated data classes, then copy to clipboard or download as a .kt file. The output is ready to paste into your Kotlin project.
Common Use Cases
Android App Development
Generate data classes from API JSON responses for use with Retrofit, Ktor Client, or OkHttp. The generated classes deserialize directly with Gson, Moshi, or kotlinx.serialization.
Kotlin Multiplatform Shared Models
Create shared data models from JSON for KMP projects targeting Android, iOS, desktop, and web. The @Serializable annotation ensures the models work across all platforms.
Spring Boot / Ktor Server
Generate data classes for Ktor or Spring Boot API request and response models. Kotlin data classes integrate seamlessly with Jackson (Spring) or kotlinx.serialization (Ktor).
Jetpack Compose UI Models
Create data classes for Jetpack Compose state holders and UI models. API responses mapped to data classes integrate cleanly with ViewModel, StateFlow, and LazyColumn.
Firebase / Firestore Models
Generate data classes from Firebase JSON documents for use with the Firebase Android SDK. Data classes with default values simplify Firestore document deserialization.
Why Use Our JSON to Kotlin Data Classes Generator?
Kotlin Serialization Support
Optionally adds @Serializable annotations for kotlinx.serialization, the recommended serialization library for Kotlin Multiplatform projects
Nested Data Class Generation
Nested JSON objects produce separate data class definitions that are clean, reusable, and follow Kotlin naming conventions
Smart Type Inference
Maps JSON values to proper Kotlin types: Int for small integers, Long for large ones, Double for decimals, Boolean for true/false, and String for text
Nullable Type Support
JSON null values produce nullable Kotlin types (String?, Int?, etc.), leveraging Kotlin's null safety to prevent NullPointerExceptions at compile time
Multi-Platform Ready
Generated data classes work on Android, iOS (via KMP), JVM server-side, and JavaScript/Wasm targets without modification
Privacy-First
Your JSON data stays in your browser. Nothing is uploaded, making it safe for internal APIs and sensitive data models
Key Features
Kotlin data class generation with val properties
Optional @Serializable annotation for kotlinx.serialization
Nested data class definitions with proper naming
List<T> for arrays with element type inference
Nullable types (String?, Int?) for null JSON values
Smart Int vs Long distinction based on value magnitude
Configurable root class name
Download as .kt file
Copy to clipboard with one click
100% client-side processing — no data leaves your browser
100% Client-Side Processing
Your data never leaves your browser
All processing happens in your browser using JavaScript. Your data is never sent to our servers or any third party. Safe for sensitive data, API keys, and production configs.
Frequently Asked Questions
Quick answers to common questions about json to kotlin data classes generator
The generator outputs standard Kotlin data classes. With the @Serializable toggle enabled, it adds kotlinx.serialization annotations. For Moshi, add @JsonClass(generateAdapter = true) manually. For Gson, the data classes work as-is with no additional annotations — Gson uses reflection by default.
Integer values within the Kotlin Int range (-2,147,483,648 to 2,147,483,647) use Int. Values larger than that use Long. This ensures IDs and timestamps from APIs are typed correctly. You can always change Int to Long (or vice versa) in the generated code if needed.
Yes. The generated data classes work directly with Retrofit and any JSON converter: Gson (GsonConverterFactory), Moshi (MoshiConverterFactory), or kotlinx.serialization (KotlinxSerializationConverterFactory). Just add the appropriate converter factory to your Retrofit builder.
JSON null values produce nullable Kotlin types (e.g., String?). This leverages Kotlin's null safety system — the compiler will force you to handle null cases, preventing NullPointerExceptions at runtime. Fields that always have values remain non-nullable.
Yes. The generated data classes work across all KMP targets: Android, iOS (via Kotlin/Native), JVM, JavaScript, and Wasm. When @Serializable is enabled, the classes can be serialized and deserialized on every platform using kotlinx.serialization.
Nested JSON objects produce separate data class definitions. For example, {"user": {"address": {"city": "NYC"}}} generates data class Address(val city: String), data class User(val address: Address), and data class Root(val user: User). Each class is independent and reusable.
The generator does not add default values automatically. After generation, you can add defaults like val name: String = "" or val count: Int = 0. Default values are particularly useful for Firestore deserialization, which requires a no-arg constructor.
Related JSON Tools
JSON to TypeScript
→
Generate TypeScript interfaces for web frontends calling your Kotlin backend
JSON to Go Struct
→
Generate Go structs — useful when your Kotlin service communicates with Go microservices
JSON to Pydantic
→
Generate Python Pydantic models for Python services in your ecosystem
JSON to Rust
→
Generate Rust structs with serde for performance-critical services
JSON Formatter
→
Format and validate JSON before generating Kotlin data classes