Generates Kotlin data classes annotated for kotlinx.serialization — String? for a
nullable field, a = null default only for one that can actually be absent.
A field that's always present but sometimes null becomes val name: String? with
no default (still required); one that can be missing entirely gets = null too, which is what
makes it optional at the call site.
This page ships no analytics and sets no cookies. The content security policy blocks network requests, so your document cannot leave the tab.
Have a JSON payload and want proper Kotlin data classes for it instead of a Map<String,
Any?>? Generate @Serializable data classes in one click, entirely in your browser.
Json Web Viewer's Types mode reads your document's actual shape — key names, nesting,
array element types, which fields are sometimes missing or null — and generates matching
Kotlin data classes, annotated for kotlinx.serialization. No server round-trip, no
account, no upload.
The subtle part it gets right: kotlinx.serialization treats a property as optional only if it has a
default value — nullability alone doesn't do it, and a String? with no default still
throws MissingFieldException when the key is absent. So a sometimes-absent field is generated
as val name: String? = null — the default is what makes it optional, and the ?
is what makes the default legal — while a field that's always present but sometimes null is
String? with no default: still required in the JSON, may be null.
Example — this JSON:
{
"id": "ord_9f21a",
"customer": {
"name": "Ada Lovelace",
"email": "ada@example.com",
"vip": true
},
"items": [
{ "sku": "book-001", "qty": 2, "price": 19.99 },
{ "sku": "mug-014", "qty": 1, "price": 12.5 }
],
"shippedAt": null
}
generates this Kotlin:
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
@Serializable
data class Root(
val customer: Customer,
val id: String,
val items: List<ItemsItem>,
val shippedAt: JsonElement?,
)
@Serializable
data class Customer(
val email: String,
val name: String,
val vip: Boolean,
)
@Serializable
data class ItemsItem(
val price: Double,
val qty: Long,
val sku: String,
)
Open this example in the editor →
The link above pre-loads the order example into Types mode. TypeScript is the default
target — select Kotlin from the language dropdown next to the mode buttons to regenerate
the same document as data classes.
No. Type generation runs entirely in your browser — your JSON never leaves the page.
No — the @Serializable annotation is what kotlinx.serialization needs, but the data classes
themselves are plain Kotlin. If you deserialize with Jackson or Gson instead, delete the annotation and
its imports; do check how your library treats missing keys, since the generated defaults encode
kotlinx.serialization's rule.
They're kept distinct: always present and never null is val name: String, present but
sometimes null is val name: String? (required, nullable), and sometimes absent is
val name: String? = null — the default value is what makes a property optional to
kotlinx.serialization, not the question mark.
Need a different target language? The same dropdown also generates TypeScript, Python, Java, and C# — plus Go and Rust.