Skip to content
ToolsOnDuty - free online tools
Developer Tools

JSON to Kotlin Data Class

Convert JSON into Kotlin data classes for Android apps.

Free foreverRuns in your browserNo sign-up

Types are inferred from the sample JSON. Fields that are null become optional; check them against your real model.

About the JSON to Kotlin Data Class

Android apps map JSON responses to Kotlin data classes, often for use with Gson, Moshi or kotlinx.serialization.

This tool reads a JSON sample and generates Kotlin data classes, inferring types for strings, numbers, booleans, lists and nested objects.

Everything runs in your browser, so your JSON stays private.

Key features

  • Generates data classes from JSON
  • Infers Int, Double, Boolean, String, List and nested types
  • Custom root class name
  • Local, private conversion

How to use

  1. 1Paste a JSON sample.
  2. 2Set the root class name if you like.
  3. 3Copy the generated Kotlin data classes.

Examples

Simple model
Input: { "id": 1, "name": "Ada" }
Output: data class Root(val id: Int, val name: String)

Each JSON field becomes a typed val in the data class.

Frequently asked questions

Which serialization libraries does this suit?
The generated data classes work with Gson, Moshi and kotlinx.serialization. You may add annotations like @SerializedName or @Json for keys that are not valid Kotlin identifiers.
How are null values handled?
A null becomes a nullable String? since the real type cannot be inferred. Change it to the correct nullable type for your model.
Does it support nested objects?
Yes. Nested objects become their own data classes and arrays become typed Lists based on the first element.