Paste JSON and get Kotlin data classes with @SerializedName for Gson
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Android projects that parse JSON with Gson need a Kotlin data class for every object, with @SerializedName wherever the property name differs from the key. Paste a response and get those classes: camelCase properties, the original key in each annotation, Int, Long or Double chosen per field, and nullable types wherever the sample shows null or some items leave a key out.
Paste or type your input.
Choose the options you need.
Press Ctrl+Enter, then copy or download.
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.
| 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 |
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.
The rest of the article, and all 6 questions about JSON to Kotlin Data Class Converter, are on the JSON to Kotlin Data Class Converter page.
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.
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.
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.