JSON to Kotlin Data Class

FreePrivateInstant
JSON input
Kotlin data class
Ctrl+Enter Generate Data Class

JSON to Kotlin Data Class Generator

Paste a JSON object and get Kotlin data class definitions with typed fields, nullable markers, and nested class generation. Handles strings, integers, doubles, booleans, lists, and nested objects. Works with Gson, Moshi, and kotlinx.serialization. Runs entirely in your browser.

Where Is This Useful?

Android Retrofit API clients
When consuming a REST API in an Android app with Retrofit, you need data classes for each response type. Paste the API JSON response and get the model classes ready to use with Gson or Moshi in seconds.
Ktor and Spring Boot backend
Building a Kotlin backend with Ktor or Spring Boot? Generate data classes from your JSON request/response shapes and use them as DTOs or serialization models immediately.
Kotlin Multiplatform (KMP)
Sharing models across Android, iOS, and web in a KMP project? Generate the base data classes here, then add @Serializable for kotlinx.serialization support in your shared module.

How to Use

  1. Paste a JSON object in the input panel
  2. Set the root class name (defaults to Root)
  3. Click Generate Data Class or press Ctrl+Enter
  4. Copy the output or download as a .kt file
  5. Add @Serializable, @SerializedName, or @JsonClass annotations as needed

Type Mapping

  • JSON string → String
  • JSON integer → Int
  • JSON float → Double
  • JSON boolean → Boolean
  • JSON null → Any?
  • JSON object → named data class
  • JSON array → List<T> with inferred element type

Frequently Asked Questions

Does this add @SerializedName or @Json annotations?

No. The generated code uses plain data class without annotations. If your JSON key names differ from Kotlin field names, add @SerializedName (Gson) or @JsonProperty (Jackson) manually.

Is this compatible with kotlinx.serialization?

Yes. The data classes work with kotlinx.serialization, Gson, Moshi, and Jackson. For kotlinx.serialization, add the @Serializable annotation to each class.

How are nullable fields marked?

Fields whose JSON value is null are typed as Any?. Non-null fields use non-nullable types. For fields that may sometimes be null in a real API, adjust the type to nullable manually.

How is this different from JSON to TypeScript?

JSON to TypeScript generates TypeScript interfaces for web frontends. Kotlin data classes are for Android, backend, or KMP projects where the type system is statically compiled.

Is my JSON uploaded anywhere?

No. Everything runs locally in your browser. Your data never leaves your machine.

Related Tools