JSON to Kotlin Converter
Generate Kotlin data classes from a JSON sample — val properties, nullable types, nested classes; ready for Android and backend projects.
Data classes, the Kotlin way
Kotlin made model classes a one-liner — data class gives you equals, hashCode, toString and copy for free. What still costs time is transcribing an API response into the right property list. Paste the sample instead: nested objects become their own data classes, arrays become List<T>, and the nullability story — Kotlin's superpower — is inferred from the data: null in the sample ⇒ String?, never-null ⇒ String.
Android, Ktor, Spring — same classes
The generated classes are serialization-framework-neutral: annotate with @Serializable for kotlinx.serialization, use them directly with Moshi's reflection adapter or Gson on Android, or as Jackson targets in Spring services. Where wire keys aren't Kotlin-friendly (snake_case, dashes), add the one-line rename annotation of your framework on the affected property — the class shape stays as generated.
Nullability is data-driven — treat it that way
A type comes out non-null only because the sample never showed null there. If the API is less disciplined than your sample, you'll meet the crash at runtime — so for critical models, prefer a sample that includes the messy cases (empty lists, missing optionals, nulls). Assemble and check the sample in the formatter first; the tree viewer makes spotting the null-bearing fields easy.
Frequently asked questions
Which serialization library do the classes target?
None specifically — that is deliberate. Plain data classes work with kotlinx.serialization (add @Serializable), Moshi, Gson and Jackson. You choose the framework; the generator does the modeling.
How does the generator decide between String and String??
From evidence: a field that is null anywhere in the sample becomes nullable. Kotlin then forces you to handle the absence — exactly the compile-time safety you use Kotlin for.
Does it work for Android projects?
Yes — data classes are the standard Android model layer. For Moshi codegen (@JsonClass) or kotlinx.serialization, add the annotation on top of the generated classes.
What about val vs var?
Properties are val — immutable models are the Kotlin default and play best with coroutines and Compose. Switch individual properties to var only where mutation is truly part of the design.