{ }jsonkit
Format
Validate
Convert
Query
Generate

JSON to Kotlin data class generator

Infer data classes, nullable fields and kotlinx.serialization names.
353 B · paste or drop a file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
✓ complete353 B → 663 B0.0 ms

About JSON to Kotlin

The JSON to Kotlin generator creates data classes from an API response, config file or fixture. Nested objects become named data classes and arrays become typed List values. Primitives map to String, Boolean, Long or Double, with Kotlin nullability where the sample needs it.

Turn on kotlinx.serialization to add Serializable and SerialName annotations. Keys that are not valid Kotlin property names become camelCase, and SerialName keeps the exact wire name. You can also add null defaults so missing optional values do not make constructors awkward.

Runs in your browser. Nothing is uploaded. Use the result as a model scaffold. Then check dates, IDs, enums, number ranges and optional fields against the API contract.

How it works

Create nested Kotlin data classes

Every object shape becomes a data class, and nested objects are named after their JSON keys. Arrays of objects are merged into one element model. Properties that appear on only some elements become nullable instead of being dropped.

Apply Kotlin null safety

Explicit nulls and keys missing from some array items produce nullable types. With nullable defaults on, those parameters also get = null, so kotlinx.serialization can decode payloads where the key is absent.

Add kotlinx.serialization annotations

Serialization mode adds the kotlinx.serialization imports and marks each class Serializable. SerialName is added when the Kotlin property name differs from the JSON key, so snake_case, kebab-case and other wire names still work.

Handle arrays and mixed values

Arrays with one element type become List<T>, including nested lists. Empty or mixed arrays use Any, because one sample cannot prove a single safe type. Replace Any when your API docs give the real shape.

Frequently asked questions

Do I need kotlinx.serialization in my project?

Only with the serialization option on. The annotations need the kotlinx.serialization library and compiler plugin. Turn the option off to get plain data classes with no serializer imports.

Why are integers generated as Long?

JSON has one number syntax and says nothing about Int or Long ranges. Long is the safer default for whole-number API values. Change a property to Int, BigInteger or a domain type when the contract guarantees a smaller range.

Can the generator recognize dates or enums?

No. In a sample, a date and an enum value are both plain strings. The generator writes String on purpose. Replace it with Instant, LocalDate, an enum or another domain type based on what you know about the API.

Is sensitive JSON uploaded?

No. Parsing and Kotlin generation run in your browser.

Sources & last verified

We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.

Found a wrong result or an outdated claim? Report an error and we will check it again.