Turn a JSON sample into Kotlin data classes for kotlinx.serialization, Gson or Moshi
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Paste a JSON sample and get Kotlin data classes for kotlinx.serialization, Gson or Moshi. Whole numbers become Int, Long past 2,147,483,647, any decimal makes a property Double, a null value makes it nullable, and a key missing from some objects becomes T? = null so all 3 libraries decode it.
Paste a JSON sample, such as an API response, into the left box.
The Kotlin data classes appear as you type, one per object, with camelCase properties and an annotation wherever a key differs.
Choose kotlinx.serialization, Gson or Moshi, var instead of val if you need it, and the root class name.
Press Copy, or Download to save Models.kt.
Kotlin reads JSON into data classes, and each object needs a class whose properties have the right types, the right nullability and a way back to their keys. This converter writes those classes from a sample, so a long API response becomes Kotlin in one paste.
How types are chosen.
| JSON value | Kotlin type |
|---|---|
| "text" | String |
| true / false | Boolean |
| 42 (whole numbers only) | Int, or Long beyond 32 bits |
| 4.5 (any decimal seen) | Double |
| null, and also a type | String?, Int? |
| only null, or mixed kinds | JsonElement? or Any? |
| [ ... ] | List<...> |
| { } empty | JsonObject or Map<String, Any?> |
| { ... } | a data class of its own |
Missing keys. All the objects of an array are merged into one class. A key that some of them leave out becomes nullable with null as its default, because kotlinx.serialization and Moshi treat a missing key without a default as an error. kotlinx.serialization also rejects keys it has no property for, so every key of the sample gets one.
Names. Properties are lowerCamelCase. Where that changes the key, as user_name to userName, the property carries @SerialName, @SerializedName or @Json(name = ...), depending on the library. Keywords such as class are written in backticks. Annotation strings escape the dollar sign, since Kotlin would read it as a template.
Options. var instead of val gives mutable properties. An empty object becomes a plain class, because a data class needs at least one property. The root class is called Root unless you name it.
Every output was checked by reading the Kotlin back and decoding 9 samples with kotlinx.serialization's default rules. Nothing you paste leaves the browser.
Paste a JSON sample into the converter and the data classes appear beside it, one per object. With kotlinx.serialization, add the plugin and decode with Json.decodeFromString<Root>(text); with Gson use Gson().fromJson(text, Root::class.java); with Moshi build an adapter for Root.
A key that some objects of an array leave out gets a nullable type and null as its default. kotlinx.serialization and Moshi both refuse a missing key unless the property has a default, so the default is what lets every object of the sample decode.
kotlinx.serialization is Kotlin's own, works on every Kotlin platform and checks types at compile time. Moshi with codegen suits Android projects that already use Retrofit and Okio. Gson is the oldest and needs no setup, but it ignores Kotlin's null safety and default values when it creates objects.
Properties are lowerCamelCase, so user_name becomes userName with @SerialName, @SerializedName or @Json(name = ...) keeping the original key. A key that is a Kotlin keyword, such as class or object, is written in backticks, which keeps the key as the property's real name.
Whole numbers become Int, or Long when a value is beyond 2,147,483,647, and a field becomes Double as soon as any sample value has a decimal part. Values of different kinds become JsonElement? with kotlinx.serialization, or Any? with Gson and Moshi.
No. The conversion runs in your browser with no request to any server, and the JSON is not stored, so API responses holding tokens or personal data stay on your device. Close the tab and nothing remains.
Rates and rules change; check the source before you rely on a figure.
Still stuck? Ask about JSON to Kotlin Data Class Converter and anybody who knows can answer. No account needed.
Same job, other tools: Image to Base64 – Get a data URI for any image, ready for CSS or HTML · TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.