JSON to Kotlin Data Class

Convert JSON to Kotlin data classes for kotlinx.serialization, Jackson or Gson

A free JSON to Kotlin converter: paste JSON and get data classes back instantly. Choose immutable val properties or mutable var ones, and pick the JSON library the annotations target: kotlinx.serialization (@SerialName), Jackson (@JsonProperty) or Gson (@SerializedName). Property types are inferred from the data, nested objects become their own classes, and keys that can be null or missing become nullable properties with a null default. Conversion runs entirely in your browser, so your JSON is never uploaded to a server.

Options on this page

Output formats: Data class (Immutable data class with val properties), Mutable (Data class with var properties).

OptionWhat it does
Root Class NameNames the top-level Data class.
Package (optional)Emitted as a package declaration at the top of each file.
Field Naming ConventionOne of camelCase, PascalCase, snake_case, Preserve Original. Defaults to camelCase.
Type for null valuesEither Any (JsonElement for kotlinx) or String, used when a key is null in every sample.
Separate ClassesWrite each class to its own .kt file. Off (the default) puts every class in one file, so Copy All pastes into a single file that compiles.
Add JSON annotationsAnnotate properties with the original JSON key — @SerialName, @JsonProperty or @SerializedName, depending on the library. Without them a property only binds to a key spelled exactly like it, so snake_case keys are not read into camelCase properties.
JSON libraryOne of kotlinx.serialization, Jackson or Gson; picks which JSON library the generated code is written for.

How JSON values map to Kotlin types

JSON valueKotlin type
stringString
integerInt
integer beyond 32 bitsLong
decimalDouble
true / falseBoolean
ISO-8601 timestampString
arrayList<T>
objectnested data class
null or missing in some samplesT? = null
nullAny? / JsonElement? (configurable)

Example

Input JSON

{
  "id": 12345,
  "product_name": "Wireless Mouse",
  "price": 24.99,
  "in_stock": true,
  "tags": ["electronics", "accessories"],
  "manufacturer": {
    "name": "Acme Corp",
    "country": "US"
  }
}

Generated Kotlin

@Serializable
data class Product(
    @SerialName("id") val id: Int,
    @SerialName("product_name") val productName: String,
    @SerialName("price") val price: Double,
    @SerialName("in_stock") val inStock: Boolean,
    @SerialName("tags") val tags: List<String>,
    @SerialName("manufacturer") val manufacturer: Manufacturer
)

Frequently asked questions

How do I convert JSON to a Kotlin data class?

Paste your JSON into the input pane and the Kotlin data classes appear beside it immediately. Pick the JSON library, set the root class name and an optional package, then copy the code or download it. Nested JSON objects become their own data classes and arrays become List<T>.

Which JSON library should I choose?

kotlinx.serialization is the Kotlin-native choice and works on every Kotlin platform; the classes are marked @Serializable and properties use @SerialName. Jackson (with jackson-module-kotlin) and Gson are the usual picks in existing JVM and Android code; they emit @JsonProperty and @SerializedName. The properties are identical apart from the annotation.

Why do some properties end in ? = null?

A key that is null or missing in at least one sample becomes a nullable property with a null default, so a payload that omits it still deserializes. A plain non-null property makes kotlinx.serialization and Jackson throw on a missing key, and Gson silently leaves it null.

Why are timestamps a String instead of a date type?

kotlinx.serialization has no built-in java.time serializer and Gson cannot reflect into java.time on recent JDKs, so there is no date type that works with all three libraries without extra modules or adapters. A String always round-trips exactly; parse it with java.time or kotlinx-datetime where you need a date.

Is my JSON uploaded anywhere?

No. Parsing, type inference, and code generation all run in your browser using JavaScript. Your JSON is never sent to a remote server, and there is no account to create. The page keeps your last input and settings in your own browser (localStorage) so they survive a reload; nothing is stored anywhere else.

Is it safe to paste confidential JSON, such as API responses or customer data?

The conversion itself never transmits your JSON, so a confidential payload does not leave your machine. You can verify this: open your browser DevTools, switch to the Network tab, and convert something — no request carries your data. Two things to know: your last input is saved in your browser's localStorage (clear site data to remove it), and the Copy Link button embeds your JSON in the link, so anyone who opens that link, and the server that receives the request, can see it. Only share such links where you are comfortable with that.

Does it cost anything?

No. The generator is free to use with no sign-up and no usage limits.

How are nested objects handled?

Each nested JSON object becomes its own named type, derived from the key it appeared under. Arrays of objects are widened across every element, so a field that is a whole number in one element and a fraction in another gets a type that holds both.

Other languages

More JSON tools