JSON to Kotlin data class converter
Paste JSON from your API and get clean Kotlin data classes – with kotlinx.serialization, Gson or Moshi annotations, nested classes, lists and nullable types. Copy or download the .kt file.
How to convert JSON to Kotlin
- Paste your JSON – for example an API response from Postman or your browser.
- Pick the library your app uses: kotlinx.serialization, Gson or Moshi.
- Copy or download the Kotlin file and add it to your data or model package.
How the types are chosen
| JSON value | Kotlin type |
|---|---|
| “text” | String |
| 42 | Int (Long if it is too big for Int) |
| 4.5 | Double |
| true / false | Boolean |
| { … } | A new nested data class |
| [ … ] | List<Type> – objects in the list are merged into one class |
| null or a key missing in some items | Nullable type with ? |
Which library should I use?
kotlinx.serialization is the Kotlin-first choice for new projects and works well with Ktor and Retrofit (via a converter). Add the serialization plugin to Gradle. Moshi is a solid choice with Retrofit and supports Kotlin through code generation. Gson is still common in older projects, but it does not understand Kotlin null safety or default values – prefer nullable properties with Gson.
Tips
- Use a full, real response – the more examples in a list, the better the tool can detect optional fields.
- Rename generated classes to clear names, for example
Ownerinstead ofOwnerItem. - Need to tidy your JSON first? Use our JSON Formatter.
Frequently asked questions
How do I convert JSON to a Kotlin data class?
Paste the JSON, choose kotlinx.serialization, Gson or Moshi, and copy the generated classes. Nested objects become their own data classes and arrays become List types.
Does it support nested JSON and arrays?
Yes. Every nested object becomes a data class, and objects inside arrays are merged so fields that are missing in some items become nullable.
Is my JSON sent to a server?
No. The conversion runs entirely in your browser, so API responses with private data stay on your device.
Why are some properties nullable?
A property is nullable when its value is null or when the key is missing in some items of a list. You can also make every property nullable with the checkbox.
Can I use the output with Retrofit?
Yes. Use the kotlinx.serialization, Moshi or Gson converter for Retrofit that matches the annotations you chose.
Need a website or app built?
We design and build websites and Android apps for clients worldwide – clear scope, fixed price, fast delivery.
Techpass Master Technologies · Websites, Android apps and digital marketing
