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

Type mapping

JSON valueKotlin type
42Int (or Long)
3.14Double
"hi"String
trueBoolean
nullAny?
[{...}]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?
The output is plain Kotlin data classes with typed vals. With kotlinx.serialization you add @Serializable and @SerialName("key") where a property name differs from its JSON key; with Gson, @SerializedName("key") does the same. The field types already match the JSON values.
How are null and nullable fields handled?
A null value in the sample becomes `Any?`, because Kotlin cannot know the intended non-null type from a null alone. A property that is genuinely optional in your real data should be `Type?`; the generator marks only nulls as `Any?` and leaves every other field non-null.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close