Developer

JSON to Kotlin Data Class

Generate Kotlin data classes from a JSON sample with nullable types, nested classes, List element types and SerialName or SerializedName annotations for keys that are not idiomatic Kotlin.

Last reviewed by the Radiatus Cloud team

Generated Kotlin appears here.

Need this built for your product?

We design, build & host secure software & APIs.

Talk to an engineer

Data classes are the Android JSON boundary

Every Android or Kotlin backend project that touches an HTTP API ends up with a folder of data classes mirroring the payloads. They are pure transcription, they are where the null safety guarantees of the language are either honoured or quietly discarded, and they are the first thing that breaks when a provider adds a field. Generating them from a real response removes the transcription error and, more importantly, makes the nullability decisions explicit rather than accidental.

Nullability is the whole point

Kotlin distinguishes String from String?, and getting that wrong is not a style issue. A field declared non null that arrives as null produces a NullPointerException deep inside the deserialiser on kotlinx.serialization, or a silently null non null property on Gson, which is worse because it violates the type system without an error. This generator marks a property nullable when the sample showed a null or the key was missing from any record, and gives it a default of null so a partial payload still constructs.

Annotations and naming

JSON keys arrive in camelCase, snake_case or kebab-case depending on the backend. Kotlin properties are camelCase, so anything else is converted and annotated with the original key using SerialName for kotlinx.serialization or SerializedName for Gson and Moshi. That keeps the class idiomatic while still deserialising the payload exactly as it arrives, and it means renaming a property later is a local change rather than a wire format change.

Related tools

  • JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
  • JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
  • Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
  • HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.

Frequently Asked Questions

kotlinx.serialization or Gson?

kotlinx.serialization is compile time, has no reflection, works on Kotlin Multiplatform and respects nullability strictly. Gson is reflective, tolerant, and will happily leave a non null property null. New projects should prefer kotlinx.serialization; Gson output is here for existing codebases.

Why does every nullable property get a default?

Because without a default, a missing key is a deserialisation error even when the type is nullable. Adding = null makes an absent key produce null, which is the behaviour people expect from an optional field.

How are numbers typed?

Whole numbers become Long rather than Int, since API identifiers routinely exceed the Int range and the failure mode is a runtime overflow. Fractional numbers become Double.

What happens to an empty array in the sample?

The element type cannot be inferred, so it becomes List<JsonElement> for kotlinx or List<Any> for Gson, and the tool flags it. Paste a response where the array has content to get a real type.

Does it generate the serializer setup?

No, only the classes and their annotations. The Json configuration, retrofit converter or Gson instance stays in your project because those settings are application wide.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Paste JSON, pick kotlinx.serialization or Gson, and copy the generated Kotlin data classes.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.