Input

Output

What does the JSON to Kotlin converter generate?

Paste a JSON sample and you get one Kotlin data class per object, with val properties in camelCase, your package line on top, and nested classes listed before the classes that use them. With kotlinx.serialization ticked (the default), each class gets @Serializable, and any property whose name differs from its key gets @SerialName("user-id"), ready for Json.decodeFromString<RootObject>(text) with the kotlinx.serialization plugin.

Types come from every value in the sample. Whole numbers are Int, Long past 32 bits, or ULong for positive values past the signed 64-bit range. Arrays become List<T>, nested arrays List<List<T>>. Values whose type varies, or that were only ever null, become JsonElement? in serialization mode and Any? otherwise, and an empty object becomes JsonObject or Map<String, Any?>. Keys that clash with Kotlin's hard keywords, like class or in, keep their name in backticks.

With Nullable Types on, a property that was null, or missing from some objects in an array, is typed String? = null, so decoding doesn't fail when the key is absent (see null safety). Without the serialization option you get plain data classes and a // JSON key: "user-id" comment next to renamed properties; add Gson's @SerializedName or Moshi's @Json(name = ...) yourself if you use those. Everything runs in your browser.

How to use it

The classes update as you type.

1

Paste a JSON sample

Paste into the Input panel, Upload a .json or .txt file, or click Sample. Example input:

{"subscriberId":"SUB-1001","plan":"Unlimited 5G","dataUsage":45.2,"status":"active"}

Set Class Name for the root class and Package for the package line. Need to check the JSON first? Use the JSON Validator.

2

Pick the options

Toggle kotlinx.serialization and Nullable Types and watch the Output panel change. For the sample you get Account, Device, Subscriber and RootObject.

3

Copy or download

Copy the code or Download a .kt file named after the root class.

Where this saves time

Android API models

Paste a response from your backend and get models for Retrofit with the kotlinx.serialization converter, including nullable defaults for fields the server sometimes leaves out.

Ktor clients and servers

Ktor's ContentNegotiation plugin works with @Serializable classes, so generated request and response types drop straight into routes and HttpClient calls.

Kotlin Multiplatform

kotlinx.serialization runs on JVM, Android, iOS and JS, so the same generated models can live in a shared module.

Finding optional fields

Paste several real records as an array. Anything absent or null in one of them becomes nullable with a = null default, which shows where your code needs a fallback.

Common Questions

Which serialization library does it target?

With the option ticked, kotlinx.serialization: @Serializable on classes and @SerialName on renamed properties. With it off you get plain data classes that Gson, Moshi or Jackson can read, but you add their rename annotations yourself.

What does Nullable Types change?

On: properties that were null or missing in the sample become nullable with a = null default. Off: they keep the non-null type, which is stricter but fails to decode if the value really is missing. Values that were only ever null stay nullable either way.

How are large integers handled?

The page reads integers exactly, so an ICCID like 8901240544102066246 gets Long. Positive values up to 18446744073709551615 get ULong; anything bigger becomes JsonElement (or BigInteger without serialization).

Has the output been compiled?

We check it against Kotlin's keyword rules and type syntax, but there's no Kotlin compiler behind this page, so give it a build in your project and review null-only fields, which come out as JsonElement? or Any?.

What if my root is an array?

The objects inside become the root class and a comment shows the List<RootObject> to decode into. A root that is null, a string or a list of plain values gives a short message instead.

Is my JSON uploaded?

No. Generation happens in your browser and nothing is sent to a server. Input is capped at 256 KB.

Other JSON Tools You Might Need

Need the same models in Java or Swift, or want to validate the JSON first?