JSON to Kotlin

Generate Kotlin Data Classes
from JSON

Paste any JSON and instantly get Kotlin data class definitions with @SerializedName annotations. Perfect for Android development and Kotlin JVM projects.

Open JSON to Kotlin Converter

Kotlin data classes in four steps

Paste your JSON Drop any valid JSON object or array into the input — as compact or pretty-printed as you like.
Select Kotlin output Switch to the Convert tab and choose Kotlin. Data class definitions are generated immediately.
Copy the data classes One-click copy puts the generated Kotlin code on your clipboard, ready to paste into your project.
Add to your Android project Paste the data classes into your codebase and add Gson or Moshi to your Gradle dependencies.

No account. No upload. No nonsense.

🔒

No Server

Your JSON never leaves your device. There is no backend to send it to.

Android Ready

Generated data classes are compatible with Gson, Moshi, and Kotlin Serialization.

📡

Works Offline

Load once and use forever — even on a plane or without internet access.

Related JSON tools

JSON to TypeScript Generate typed TypeScript interfaces from your JSON structure instantly.
JSON to Go Generate Go struct definitions with JSON tags from any JSON input.
JSON Formatter Pretty-print JSON with syntax highlighting and a collapsible tree view.
JSON Schema Validator Validate JSON against a Draft-07 schema with detailed error messages.

Common questions answered

Is JSON to Kotlin conversion free?

Yes, completely free with no account required.

What serialization library is used?

The output is compatible with Gson (@SerializedName) and Moshi. You can also use Kotlin Serialization by replacing @SerializedName with @SerialName.

Does my data leave my browser?

No. All conversion is 100% client-side — your data never leaves your device.

How are nullable fields handled?

Fields that could be null in JSON are typed as nullable (e.g., String?) in the generated Kotlin code.

Are nested objects supported?

Yes. Each nested JSON object becomes a separate data class, and arrays become List<T>.

Converting JSON to Kotlin data classes

Kotlin data classes provide equals(), hashCode(), toString(), and copy() automatically. Combined with kotlinx.serialization or Gson, data classes make JSON deserialization type-safe and concise. This tool generates Kotlin data class definitions with proper types (String, Int, Double, Boolean), nullable handling (String?), and @SerialName annotations.

The converter produces idiomatic Kotlin: val properties for immutability, nullable types for optional fields, List<T> for arrays, and nested data classes. When JSON keys use snake_case, it adds @SerialName annotations. The output works with kotlinx.serialization, Gson, Moshi, and Jackson.

Convert JSON to Kotlin data classes
Input
{
  "user_name": "Alice",
  "age": 30,
  "roles": ["admin"],
  "bio": null
}
Output
@Serializable
data class Root(
    @SerialName("user_name")
    val userName: String,
    val age: Int,
    val roles: List<String>,
    val bio: String?
)

Get the most out of this tool

Ready to generate your Kotlin data classes?

Free forever. No signup. Instant results.

Open JSON to Kotlin Converter

Kotlin data classes for JSON explained

Kotlin is the primary language for Android development and is increasingly used for server-side development with frameworks like Ktor and Spring Boot. Kotlin's data class feature is ideal for representing JSON: a single line declares a class with constructor parameters, equality checks, toString, and copy methods automatically. Combined with kotlinx.serialization or Gson, Kotlin data classes provide a clean, concise way to work with JSON APIs.

The converter generates Kotlin data classes with proper Kotlin type conventions. JSON strings become String, numbers become Int or Long (for integers) and Double (for floats), booleans become Boolean, null-capable fields use nullable types (String?), and arrays become List<T>. Field names are converted to camelCase to follow Kotlin naming conventions, while the @SerializedName or @JsonProperty annotations preserve the original JSON key for serialization.

Kotlin's null safety system is particularly important for JSON deserialization. JSON fields can be absent or null — Kotlin distinguishes these with nullable types (String? can be null) versus non-nullable types (String cannot be null). When a JSON field might be missing, marking it as nullable with a default null value prevents NullPointerExceptions during deserialization. The converter infers nullability from the data sample, but you should review and adjust based on your API's documented contract.

For Android development specifically, Kotlin data classes work with both Gson (Google's JSON library, widely used in Android) and kotlinx.serialization (JetBrains' multiplatform serialization library). The @SerializedName annotation is Gson-specific. The @SerialName annotation is for kotlinx.serialization. The converter generates Gson annotations by default — if you use kotlinx.serialization, replace @SerializedName with @SerialName from the kotlinx.serialization.SerialName import.

Retrofit, the most popular HTTP client library for Android, uses Gson or Moshi as its JSON converter. When you define a Retrofit API interface returning a data class, Retrofit automatically deserializes the JSON response into your data class. The generated Kotlin data classes from this tool are directly compatible with Retrofit + Gson — you can paste them into your Android project and use them as Retrofit response types immediately.

Kotlin multiplatform (KMP) projects can share data class definitions between Android, iOS (via Kotlin/Native), and server-side (JVM) code. Using kotlinx.serialization (which is multiplatform-compatible unlike Gson), you can define the data classes once and use them across all platforms. This is a major advantage of Kotlin over Java or Swift — a single source of truth for your data model shared across the entire application.

When developers use this tool

Android API integration When integrating a new REST API into an Android app, generate Kotlin data classes from the API's JSON response to use directly with Retrofit and Gson or Moshi for automatic deserialization.
Ktor server-side development Ktor applications use data classes for request and response bodies. Generate Kotlin data classes from your API contract's JSON examples to use as Ktor content negotiation types.
Kotlin Multiplatform model sharing Generate the base data class structure for a KMP project. The class will work on Android and JVM with minimal modification — add @Serializable from kotlinx.serialization and the class is multiplatform-ready.
Migrating Java code to Kotlin When converting Java POJO classes that represent JSON to Kotlin, generate the equivalent Kotlin data class and compare — often a multi-line Java class compresses to a single-line Kotlin data class.

Additional frequently asked questions

Should I use Gson, Moshi, or kotlinx.serialization?

For new Android projects, kotlinx.serialization is recommended because it is Kotlin-first, multiplatform-compatible, and fully null-safe. Moshi is a popular alternative with good Kotlin support via the moshi-kotlin-codegen processor. Gson is the most legacy-compatible but was not designed for Kotlin's null safety model.

How do I handle JSON fields with names that are Kotlin keywords?

Kotlin keywords like object, class, in, or fun cannot be used as property names directly. Backtick-escape them: val `object`: String, or use the @SerializedName annotation to map a safe Kotlin name to the JSON key: @SerializedName("object") val jsonObject: String.

Can I use the generated data classes with Room database?

Kotlin data classes can be used with Room if you add @Entity annotation and define a @PrimaryKey. Room does not support nested objects or lists as column types — use @Embedded for nested objects or @TypeConverter for lists. The generated data class is a good starting point for your Room entity design.

What is the difference between a Kotlin data class and a regular class?

A Kotlin data class automatically generates equals(), hashCode(), toString(), and copy() methods based on the primary constructor parameters. Regular classes require you to implement these manually. For JSON models, data classes are almost always the right choice because equals() enables value comparison for testing and copy() enables immutable update patterns.