JSON to Kotlin Data Class Generator
Convert JSON into Kotlin data classes with typed, nullable-aware fields and List generics. Handles nesting and arrays. Runs entirely in your browser.
Input JSON
How it works
- Paste a JSON sample and click Generate Kotlin.
- Each object becomes a
data class; arrays becomeList<T>; nulls becomeAny?. - Nothing leaves your browser.
Type mapping
| JSON value | Kotlin type |
|---|---|
42 | Int (or Long) |
3.14 | Double |
"hi" | String |
true | Boolean |
null | Any? |
[{...}] | List<Nested> |
About JSON to Kotlin
Kotlin data classes are the natural fit for JSON models, but hand-writing them for a nested payload is repetitive. This generator reads a sample and emits data classes you can paste into a model package, with types inferred from the values it sees.
Inference reflects only the sample: a field missing from the sample is missing from the output, a null becomes Any?, and a heterogeneous array becomes List<Any>. Add serial-name annotations where your property names differ from the JSON keys.
Type inference
Integers become `Int`, widening to `Long` past 2,147,483,647; fractional numbers become `Double`; booleans become `Boolean`; strings become `String`. A JSON array becomes `List<T>`, folding object elements into one data class and collapsing primitives to their common type.
A null in the sample becomes `Any?` — Kotlin has no JSON `null` representation, and a single null reveals nothing about the intended type, so `Any?` is the honest placeholder you then refine to the real type.
Naming and structure
Each object becomes a `data class`, named after the key that held it with the first letter capitalised. Fields keep the JSON key as the property name when it is a legal Kotlin identifier; otherwise it is sanitised and you would add a serial name annotation.
Data classes nest freely, so a deeply nested payload becomes a tree of small classes. Collisions across keys that capitalise alike get a numeric suffix rather than two classes with the same name.
What you get
The output is a set of `data class` definitions — a ready-to-paste model layer skeleton, not a validation or adapter layer. You would add serialisation annotations and `Type?` for fields that are optional in production but were present in the sample.
Conversion runs entirely in your browser: the JSON is parsed and walked by JavaScript, nothing is uploaded, and there is no server call.
Frequently Asked Questions
Will the data classes serialise with kotlinx.serialization or Gson?
How are null and nullable fields handled?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.