{ JSON to Kotlin Data Class }

// turn json into kotlin data classes in one click

Convert JSON to Kotlin data classes instantly. Supports nullable fields, nested objects, arrays, and idiomatic Kotlin naming conventions. Free, browser-based.

Paste your JSON object or array below
โŸจKโŸฉ

Kotlin classes will appear here

Paste JSON and click Generate

HOW TO USE

  1. 01
    Paste your JSON

    Drop any JSON object or array into the left panel

  2. 02
    Configure options

    Set root class name, nullability, and annotation style

  3. 03
    Generate & copy

    Click Generate โ€” copy individual classes or all at once

FEATURES

Kotlin Idiomatic Nested Objects Nullable Fields @SerializedName camelCase Convert List Support

USE CASES

  • ๐Ÿ“ฑ Android API response models
  • ๐Ÿ”ง Retrofit / Gson / Moshi DTOs
  • ๐Ÿงช Rapid prototyping Kotlin apps
  • ๐Ÿ“ฆ Ktor server data models

WHAT IS THIS?

This tool converts any JSON structure into idiomatic Kotlin data class declarations. It infers types, converts snake_case keys to camelCase properties, handles nested objects by generating separate classes, and optionally adds @SerializedName annotations for Gson compatibility.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

Does this tool handle nested JSON objects?

Yes. Nested JSON objects are extracted into separate Kotlin data classes. Each nested object gets a class name derived from its parent key in PascalCase. For example, a key user_address containing an object becomes a UserAddress data class.

How are JSON arrays converted?

JSON arrays become List<T> fields in Kotlin. If the array contains objects, the tool generates a class for the item type. Primitive arrays like string lists become List<String>. Empty arrays default to List<Any>.

What does the "All Nullable" option do?

When enabled, every generated field is marked as nullable (e.g. String? instead of String). This is useful when your API responses may omit fields, and you want to be safe without having default values.

Is @SerializedName added automatically?

When the "@SerializedName" option is enabled (default), the tool adds @SerializedName("original_key") annotations whenever the JSON key differs from the Kotlin property name โ€” for example when snake_case is converted to camelCase.

How does type inference work?

Types are inferred from the JSON values: JSON booleans โ†’ Boolean, integers โ†’ Int, decimals โ†’ Double, strings โ†’ String, null values โ†’ Any?. Nested objects and arrays are handled recursively.

Does this work with Moshi or kotlinx.serialization?

The generated classes are standard Kotlin data classes that work with any serialization library. The @SerializedName annotation is Gson-specific. For Moshi use @Json(name = "..."), and for kotlinx.serialization use @SerialName("...") โ€” these are easy manual substitutions.

Can I change the root class name?

Yes โ€” the "Root Class Name" input at the top lets you set any name for the top-level class. It will be converted to PascalCase automatically. Nested class names are inferred from their JSON key names.

Is this tool free? Is my JSON data stored?

Completely free โ€” no sign-up required. All conversion happens client-side in your browser. Your JSON data is never sent to a server or stored anywhere.

JSON to Kotlin Data Class Generator

Converting JSON API responses into strongly-typed Kotlin models is one of the most repetitive tasks in Android and Kotlin development. Whether you're building with Retrofit, Ktor, or plain HTTP clients, you need Kotlin data classes that accurately reflect your JSON schema. This tool automates that process, giving you clean, idiomatic Kotlin code in seconds.

๐Ÿ’ก Looking for premium web development assets? MonsterONE offers unlimited downloads of templates, UI kits, and assets โ€” worth checking out.

What is a Kotlin Data Class?

A data class in Kotlin is a special class designed to hold data. Unlike regular classes, the compiler automatically generates useful methods like equals(), hashCode(), toString(), and copy(). This makes them ideal for representing API responses, database records, and any value objects in your application.

When you receive JSON from a REST API, you typically want to deserialize it into a structured Kotlin model. Serialization libraries like Gson, Moshi, and kotlinx.serialization all work seamlessly with data class declarations.

Handling Nullable Fields in Kotlin

One of Kotlin's standout features is its null safety system. Fields that may be absent in a JSON response should be declared as nullable types (e.g. String?) with a default value of null. The generator handles this in two ways:

Getting nullability right prevents NullPointerExceptions at runtime and makes your code more reliable. Kotlin forces you to handle null cases explicitly, which is a significant advantage over Java models.

Nested Objects and Recursive Generation

Real-world JSON is rarely flat. A user object might contain an address object, which itself contains a city and country. This generator handles nested structures by creating separate data class declarations for each nested object. The class name is derived from the JSON key in PascalCase โ€” so a field named shipping_address produces a ShippingAddress data class.

For arrays of objects, the generator infers the item type from the first element and produces a List<ClassName> field. This covers the majority of common API patterns.

snake_case to camelCase Conversion

JSON APIs commonly use snake_case keys (e.g. created_at, user_id), while Kotlin conventions prefer camelCase (e.g. createdAt, userId). The generator automatically converts all keys during class generation. When the @SerializedName option is enabled, an annotation is added to map the original key name to the renamed Kotlin property โ€” ensuring Gson serializes correctly.

Using Generated Classes with Gson

With the @SerializedName option enabled, the generated classes are ready to use directly with Gson:

val gson = Gson()
val user = gson.fromJson(jsonString, Root::class.java)

The annotations ensure that even though your Kotlin properties use camelCase, Gson correctly maps them to and from the snake_case JSON keys.

Using Generated Classes with Moshi

For Moshi users, simply replace @SerializedName("key") with @Json(name = "key") and add the Moshi dependency. The rest of the data class structure is identical. Moshi also supports Kotlin's null safety more natively than Gson, making it a popular choice for modern Android projects.

kotlinx.serialization Support

If you're using the official Kotlin serialization library, add the @Serializable annotation to each class and replace @SerializedName with @SerialName. The generated structure maps directly to this pattern. kotlinx.serialization is the recommended approach for multiplatform Kotlin projects (KMP), as it works consistently on JVM, JS, and Native targets.

Best Practices for Kotlin API Models

Why Use a Generator Instead of Doing It Manually?

Manual conversion from JSON to Kotlin data classes is tedious and error-prone. For a response with 20+ fields, you might spend 10 minutes writing the class, and another 10 debugging a typo in a field name. A generator eliminates this entirely โ€” paste, click, done. It also ensures consistency in naming conventions across all your models, which matters in large codebases with multiple contributors.

โ˜•