JSON Input

Kotlin Output

What Is JSON to Kotlin?

When you're building an Android app or a Kotlin backend service and you get a JSON API response, you need Kotlin data classes that match the structure before you can deserialize anything. Writing them by hand — especially with deeply nested objects — is slow and easy to get wrong. This tool generates Kotlin data classes automatically from your JSON. Paste a sample response and you'll get ready-to-use models for kotlinx.serialization or Gson in seconds.

Conversion runs in your browser. Set the data class name and package in the config. Enable Data Class for data class syntax and Nullable Types for optional fields. Nothing is sent to a server.

How to Use This Tool

1

Paste or Upload JSON

Paste your JSON into the left editor or upload a file. Use Sample for example data. Set the root data class name and package in the config. Enable Data Class and Nullable Types as needed.

2

Review the Generated Types

The right panel shows Kotlin data classes. Nested objects become nested types. Arrays become List<T>. Use @SerializedName or @Json if JSON keys differ from property names. For invalid JSON, use the JSON Formatter or JSON Validator first.

3

Copy or Download

Use Copy or Download. Paste into your Android or Kotlin project. For formatting JSON first, use the JSON Formatter. For validation, use the JSON Validator.

JSON to Kotlin Examples

Here is an example of generating Kotlin data classes from a JSON object.

Example: Subscriber record

JSON input:

Input

Generated Kotlin output:

Output

When JSON to Kotlin Helps

When building Android apps or Kotlin backend services that consume REST APIs, you need typed data classes. Paste a sample response here to get Kotlin models for Retrofit, Gson, or kotlinx.serialization. For API testing, Postman helps.

Frequently Asked Questions

How do Kotlin data classes work with JSON?

A Kotlin data class holds structured data with auto-generated equals, hashCode, toString, and copy methods. Libraries like Gson and kotlinx.serialization use the class properties to map JSON fields. Generate the data class here, add the right annotations, and deserialize with Gson.fromJson or Json.decodeFromString.

How do I parse JSON with Retrofit in Kotlin?

Add a Gson or kotlinx.serialization converter factory to your Retrofit builder, then define your API interface with a data class return type. Generate the data class from your API response here, paste it into your project, and Retrofit will handle the deserialization automatically.

What's the difference between @SerializedName and @SerialName in Kotlin?

@SerializedName is for Gson and maps a JSON key to a Kotlin property name. @SerialName is the kotlinx.serialization equivalent. Use whichever matches your JSON library. Both let you have JSON keys like user_name map to a Kotlin property named userName.

Is my JSON sent to a server?

No. The data class generation runs entirely in your browser. Your JSON never leaves your machine.

Nullable types in Kotlin data classes?

Enable Nullable Types to generate String?, Int?, etc. This is useful when a JSON field can be absent or null. Kotlin's null safety means you'll get a compile error if you forget to handle these cases.

Related Tools

For Kotlin JSON, see kotlinx.serialization and Gson. For JSON, see the JSON specification and RFC 8259. For a general overview, see MDN.