JSON to Kotlin
Paste JSON and get quicktype-style Kotlin data classes with inferred types, nested classes, and kotlinx.serialization annotations.
Example
Given this JSON:
{ "id": 1, "name": "Ada", "tags": ["math"], "address": { "city": "London", "zip": null } }the tool emits:
import kotlinx.serialization.Serializable
@Serializable
data class Root(
val id: Int,
val name: String,
val tags: List<String>,
val address: Address
)
@Serializable
data class Address(
val city: String,
val zip: Any?
)
Note zip is typed Any? because its only value was null.
How it works
Parses your JSON, walks every value to infer Kotlin types (Int, Double, Boolean, String, List, nested data class), and emits @Serializable data classes with the root named Root. Object arrays are merged so any key missing from some elements becomes nullable.
Good to know
JSON to Kotlin turns a sample JSON payload into ready-to-use Kotlin data class declarations annotated for kotlinx.serialization. It is aimed at Android and Kotlin backend developers who receive JSON from an API and want a typed model to deserialize into, without hand-writing every field. Paste a representative response, click Convert, and the tool walks the structure to infer types and produce one class per object shape, with the top-level value named Root.
Reach for it whenever you are wiring up a new endpoint, prototyping against a third-party API, or migrating loosely typed code to strongly typed models. It is also handy for spotting inconsistencies in a payload: because object arrays are merged, a key that appears in only some elements is automatically marked nullable, which surfaces optional fields you might otherwise miss.
Reading the output is straightforward once you know its conventions. A ? suffix means the field can be null or absent; a field typed Any? means the only value the tool ever saw for that key was null, so it could not guess a concrete type. Keys that are not valid camelCase identifiers (such as created_at) get a camelCase property name plus a @SerialName("original_key") annotation so JSON round-trips correctly, and the matching import is added only when needed.
One practical caveat: the generated types are only as good as the sample you feed it. Use the most complete, real-world payload you have, ideally an array containing several objects, so optional fields and varied value types are captured. After generating, manually review any Any? fields and tighten them to a concrete type, and double-check that integers the tool typed as Int will not overflow at runtime, switching them to Long where large IDs or timestamps are possible.
Frequently asked questions
How are nullable and optional fields decided?
For arrays of objects, all element keys are merged: a key missing from some elements, or holding a null in any element, becomes nullable (suffixed with ?). A field whose only seen value is null is typed Any?.
Does it generate annotations for snake_case or kebab-case keys?
Yes. JSON keys that are not valid camelCase Kotlin identifiers are converted to camelCase property names, and a @SerialName("original_key") annotation plus the matching import are added so kotlinx.serialization round-trips correctly.
Is my data uploaded anywhere?
No — it runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.
People also ask
How does the tool decide between Int and Double for numbers?
It inspects each numeric value: whole numbers with no fractional part are typed Int, and any number with a decimal point is typed Double. It does not widen to Long, so very large IDs may need a manual change.
Does JSON to Kotlin support kotlinx.serialization out of the box?
Yes. Every generated class carries a @Serializable annotation and the import for kotlinx.serialization.Serializable is included automatically, with the SerialName import added only when a renamed key requires it.
What does an Any? type in the generated Kotlin mean?
Any? appears when the only value the tool observed for that key was null, so no concrete type could be inferred. You should replace it with the real type once you know what non-null values look like.
Can it convert an empty JSON array or an empty object?
An empty array becomes List<Any?> because there are no elements to infer from, and an object with no keys produces a class with no properties. Provide populated samples for accurate types.
How are nested objects named in the output?
Nested objects become their own data classes named after the key that holds them, converted to PascalCase, and arrays use a singularized form of the key name. Duplicate names are disambiguated with a numeric suffix.
Will the generated Kotlin compile without changes?
In most cases it compiles as long as the kotlinx-serialization plugin and runtime are on your classpath. Review Int versus Long sizing and any Any? fields, which may need manual adjustment for production code.
Is JSON to Kotlin the same as quicktype?
It follows a similar quicktype-style approach of inferring data classes from sample JSON, but it runs entirely client-side in your browser and targets Kotlin with kotlinx.serialization specifically.
Does my JSON get sent to a server when I use this tool?
No. The conversion runs entirely in your browser using local JavaScript, so the input never leaves your device and the tool works offline once the page has loaded.
Related tools