JSON to Kotlin Data Class Generator
Turn JSON into Kotlin data classes with nullable types, List<T>, nested classes and kotlinx.serialization, Gson or Moshi annotations.
kotlinx.serialization needs the plugin: id("org.jetbrains.kotlin.plugin.serialization") in build.gradle.kts, plus the kotlinx-serialization-json dependency.
JsonElement is used where every sample was null or where samples mix different kinds of values — replace it with the real type once you know it.
Whole numbers become Int, or Long beyond ±2,147,483,647. A number written as 10.0 is read as a whole number — include one sample with a fraction to get Double. Dates stay String.
Android and Kotlin backends usually parse JSON into data classes. Paste a sample response and get Kotlin data classes ready for kotlinx.serialization, Gson or Moshi: nested objects become their own classes, arrays become List<T>, values that are null or missing in some samples become nullable, and snake_case keys become camelCase properties with the original key kept in @SerialName, @SerializedName or @Json. Numbers beyond the Int range become Long.
How to use this tool
- Paste a representative JSON sample — arrays with several items give the best types.
- Enter the root class name and, optionally, a package.
- Pick kotlinx.serialization, Gson, Moshi or no annotations.
- Choose val or var, when properties are nullable, and whether to add default values.
- Copy the code into a .kt file.
Formula
whole number → Int (Long beyond ±2,147,483,647) · fraction → Double · true/false → Boolean · text → String · [ … ] → List<T> · { … } → data class
Values at the same place in different samples are merged: Int and Double become Double, mixed kinds become JsonElement (kotlinx) or Any. A property that is null in some sample or missing from some array item is nullable. Identical shapes share one class; list item classes are named from the singular of the key (orders → Order). Hard keywords such as in or object are written in backticks.
Example
The sample user gives three classes. User has id: Int, name: String, isActive: Boolean (annotated @SerialName("is_active")), balance: Double, followers: Long (3,000,000,000 is over Int.MAX_VALUE), tags: List<String>, address: Address, orders: List<Order> and manager: JsonElement? = null. Order has orderId: String, total: Double, items: Int and coupon: String? = null, because only the second order has a coupon.
Frequently asked questions
Which library should I choose?
kotlinx.serialization is the Kotlin-first choice and works on every Kotlin platform. Moshi with code generation is popular on Android. Gson still works but does not understand Kotlin null-safety or default values.
Why do some properties have = null?
With the default setting, nullable properties get = null so a missing key does not fail decoding. Choose "None" for strict classes or "For every property" to give non-null properties defaults too.
Why is a value typed JsonElement or Any?
Every sample was null, or the samples mix kinds such as numbers and text. Paste a sample with a real value, or set the type by hand.
Does it detect dates?
No — JSON has no date type and each library needs its own adapter for dates, so ISO date strings stay String.
Sources
Last updated:
Page address with these inputs: https://kakao.mobile/tools/json-to-kotlin-data-class/
Cite or embed this tool
kakaoCalc. (2026, November 8). JSON to Kotlin Data Class Generator. https://kakao.mobile/tools/json-to-kotlin-data-class/
“JSON to Kotlin Data Class Generator.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/json-to-kotlin-data-class/.
Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms