JSON to Kotlin Data Class
Paste JSON and generate clean, ready-to-paste Kotlin data classes with nested models, nullable types, and serialization annotations.
Input JSON
Generated Kotlin
Your generated Kotlin data classes will appear here.About JSON to Kotlin Data Class
This free tool turns any JSON object or array into idiomatic Kotlin data classes in one click. It inspects your JSON, infers the most specific type for every field, and generates strongly-typed classes you can paste straight into an Android app, a Ktor service, or any Kotlin project.
It picks the right primitive for each value — Int or Long depending on the number's size, Double for decimals, Boolean, and String — and builds nested data classes for inner objects and List<T> types for arrays. Fields that are null or only present in some array items become nullable Kotlin types. JSON keys in snake_case are converted to camelCase property names, with a serialization annotation added so the original key still maps correctly.
Output works with the most common Kotlin JSON libraries: kotlinx.serialization (@Serializable / @SerialName), Moshi (@JsonClass / @Json), Jackson (@JsonProperty), and Gson (@SerializedName) — or a plain data class with no dependencies. Everything runs entirely in your browser, so your JSON never leaves your device.
How to Use JSON to Kotlin Data Class
- Paste a JSON object or array into the input box, or click Load Sample to try it.
- Set the root class name and package name for the generated file.
- Choose your serialization library so the correct annotations are added.
- Pick a date type and toggle nullable defaults,
var/val, and empty-list defaults to match your style. - Copy the generated Kotlin and paste it into your project.
Any or Any? when a safe, more specific Kotlin type cannot be inferred.What it handles
- ✅ Nested data classes
- ✅ Root arrays via
typealias - ✅ Nullable types and
= nulldefaults - ✅
IntvsLongdetection - ✅ kotlinx, Moshi, Jackson & Gson
- ✅
snake_case→camelCase
FAQ
Does this tool send my JSON to a server?
No. All parsing and code generation happens in your browser, so your JSON stays on your device.
Which serialization libraries are supported?
kotlinx.serialization, Moshi, Jackson, and Gson. You can also choose None for a plain data class with no annotations or dependencies.
How are JSON keys like created_at handled?
They become camelCase properties (createdAt), and a name annotation such as @SerialName("created_at") is added so serialization still maps to the original key.
Does it support root-level JSON arrays?
Yes. A root array generates a typealias Root = List<Item> plus a data class for the element shape.
When does a field become nullable?
When its value is null, or when it is missing from some objects in an array. Nullable fields get a ? type and, if enabled, a = null default.
How does it choose between Int and Long?
Whole numbers within the 32-bit Int range become Int; larger values become Long. Decimals become Double.