JSON to Kotlin

Turn JSON into Kotlin data classes for kotlinx.serialization, with SerialName and nullable defaults. Free and runs in your browser.

How to convert JSON to Kotlin

  1. Paste a JSON object or array, for example a response from the API you are calling.
  2. Set the name of the root type.
  3. Copy the generated Kotlin code into your project.

What you get

Tips for accurate results

The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.

Frequently asked questions

Is my JSON sent to a server?

No. The code is generated in your browser, so API responses and other private data never leave your device.

How do I parse the JSON?

Apply the kotlinx.serialization plugin, then call Json.decodeFromString<Root>(text). Use Json { ignoreUnknownKeys = true } if the API may add fields.

Does it work with Moshi or Gson?

The classes are plain Kotlin. Replace @SerialName with @Json(name = …) for Moshi or @SerializedName for Gson, and remove @Serializable.

Why Long and Double?

Whole numbers become Long so large IDs fit, and numbers with decimals become Double. Change them to Int or Float if you prefer.