Skip to content

JSON to Kotlin Data Class

Generate Kotlin data classes with Gson or kotlinx.serialization annotations.

Serialisation library

Quick Tool Overview

The JSON to Kotlin Data Class converter generates data classes with camelCase properties, an annotation carrying the original JSON key, and nullable types with defaults for keys that are not always present.

What it does
Generates Kotlin data classes from a JSON sample
You give it
A JSON payload, ideally an array of records
You get back
Data classes for Gson or kotlinx.serialization
Best for
Android apps and Kotlin services consuming an API
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the JSON to Kotlin Data Class

A Kotlin data class is the shortest way to model a payload, and this writes them for you: one per nested object, with the property names in camelCase and an annotation carrying the original JSON key.

Both serialisation libraries are supported. Gson mode emits SerializedName, which is what most existing Android projects use; kotlinx.serialization mode emits Serializable and SerialName, which is the multiplatform-friendly choice. Fields that are absent from some records are declared nullable with a null default, so deserialisation does not throw on a payload that legitimately omits them.

Key features of the JSON to Kotlin Data Class

Both serialisation libraries

Gson's SerializedName for existing Android projects, or Serializable and SerialName for kotlinx.serialization and Multiplatform.

Safe nullability

A key missing anywhere in the sample becomes a nullable property with a null default, so deserialisation does not throw on a partial payload.

One file is fine

Kotlin does not tie file names to type names, so the whole output can live in a single Models.kt.

Data class benefits

equals, hashCode, toString and copy come free, which is exactly what a payload model needs and nothing more.

Safe numeric widths

Long and Double are used because millisecond timestamps and database identifiers regularly exceed the 32-bit range.

How to use the JSON to Kotlin Data Class

  1. 1

    Paste the JSON

    An array of records detects optional fields better than one object.

  2. 2

    Pick a library

    Gson for most Android projects, kotlinx.serialization for Kotlin Multiplatform.

  3. 3

    Name the root class

    Nested classes take their names from their keys.

  4. 4

    Copy into your project

    Paste into a .kt file — several data classes can share one file in Kotlin.

Frequently asked questions

kotlinx.serialization if you are starting fresh: it is compile-time, reflection-free and works on Kotlin Multiplatform. Gson if the project already uses it, since mixing two serialisers is rarely worth it.

Reviews of the JSON to Kotlin Data Class

What people who use the JSON to Kotlin Data Class think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the JSON to Kotlin Data Class. It takes half a minute and no account.

Write the first review

More developer tools