JSON to Kotlin Data Class
Generate Kotlin data classes from JSON, for kotlinx.serialization, Gson, or plain Kotlin.
Runs in your browser. Nothing is uploaded.
Waiting for JSON
Kotlin types appear here.What this does
Paste JSON and get Kotlin data classes for it. Pick kotlinx.serialization (@Serializable), Gson (@SerializedName), or plain classes with no annotations.
Nullable and optional
A key that is missing from some items, or sometimes null, becomes a nullable type with a default of null, like val note: String? = null. Whole numbers are Long, decimals Double.
Names
Properties are camelCase. When that differs from the JSON key (first-name → firstName) the original key is kept in a @SerialName or @SerializedName annotation. Two objects with the same shape share one class.
Using the kotlinx output
Apply the serialization plugin in Gradle, kotlin("plugin.serialization"), and add the kotlinx-serialization-json library. Then decode with Json.decodeFromString<Root>(text). By default kotlinx throws when the JSON has a key the class does not declare, so if the API may add fields, use Json { ignoreUnknownKeys = true }. A key missing from the JSON is fine only if the property has a default, which is why the tool gives every nullable or sometimes-missing property = null. Values with no single type become JsonElement, since kotlinx cannot decode Any.
Gson and plain classes
With Gson, @SerializedName keeps the original key. Be aware that Gson can create objects without calling the Kotlin constructor, so a property declared non-null may still end up null at runtime when its key is missing, and constructor defaults may be skipped. If your data is irregular, turn on All optional so every property is nullable. Plain classes have no annotations, so property names must match the JSON keys or be mapped by whatever library you use. Kotlin keywords used as keys, such as object or in, are kept with backticks.
More json tools
All json tools- JSON to TypeScriptTurn any JSON into TypeScript interfaces. Nested types named, optional keys detected.
- JSON to Go StructGenerate Go structs with json tags from any JSON. Nested structs named, pointers for nullable values.
- JSON to Java ClassGenerate Java records or POJO classes with Jackson annotations from any JSON.
- JSON to Python DataclassGenerate Python dataclasses, Pydantic models, or TypedDicts with type hints from any JSON.
- JSON to C# ClassGenerate C# classes for System.Text.Json or Newtonsoft from any JSON. Nullable types detected.
- JSON to Dart ClassGenerate null-safe Dart classes with fromJson and toJson from any JSON. Made for Flutter.
- JSON to Swift CodableGenerate Swift Codable structs with CodingKeys from any JSON.
- JSON to Rust StructGenerate Rust structs with serde derives and Option fields from any JSON.