JSON to Kotlin Classes

Generate Kotlin Data Classes from JSON. 100% client-side. Supports kotlinx.serialization, Gson, nullable types, and nested object extraction.

100% private · runs locally

Convert any JSON payload into production-ready Kotlin data classes instantly. This tool automatically infers standard Kotlin types (Int vs Double), converts keys to idiomatic camelCase, and annotates them correctly for your preferred parsing library (kotlinx.serialization or Gson). Nested JSON objects are automatically extracted into distinct, flat data class definitions.

JSON input
Kotlin Data Classes Kotlin

Related tools

Frequently asked questions

What is a Kotlin Data Class?

A Kotlin data class is a class whose main purpose is to hold data. The compiler automatically derives standard functionality like equals(), hashCode(), toString(), and copy() from all properties declared in the primary constructor. This makes them the perfect candidate for representing parsed JSON objects.

kotlinx.serialization vs Gson vs Jackson?

kotlinx.serialization is the official Kotlin multiplatform serialization library, highly optimized and tightly integrated with the language. Gson is a mature Java library by Google, very popular in Android, but lacks native understanding of Kotlin features like default arguments. Jackson is the most popular Java JSON parser, highly customizable, and works well with Kotlin via the jackson-module-kotlin plugin.

How do I handle nullable properties in Kotlin?

In Kotlin, the type system distinguishes between nullable and non-nullable types. If a JSON property might be missing or explicitly null, you should declare it with a question mark (e.g., String?). You can toggle the "All fields nullable" option in this tool to automatically append ? and a default = null to every generated field.

How are JSON keys mapped to Kotlin properties?

Kotlin properties conventionally use camelCase. If your JSON uses snake_case (like "first_name"), the tool converts the Kotlin property to firstName and adds an annotation depending on your chosen framework (e.g., @SerialName("first_name") for kotlinx or @SerializedName("first_name") for Gson).

How do I use the generated code with Retrofit?

If you are using Retrofit for network calls on Android, you can use the generated data classes as the return types for your API interface functions. Make sure you add the corresponding converter factory (like GsonConverterFactory or the kotlinx serialization converter) to your Retrofit.Builder().