{ }jsonkit
Format
Validate
Convert
Query
Generate
→kt

JSON to Kotlin Data Class Generator

Infer data classes, nullability 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, configuration document or fixture. Nested JSON objects become named data classes, arrays become typed List values, and primitive values map to String, Boolean, Long or Double with Kotlin nullability where the sample requires it.

Turn on kotlinx.serialization to add Serializable and SerialName annotations for direct use with Kotlin's multiplatform serializer. Keys that are not safe Kotlin property names are normalized to camelCase while SerialName keeps the exact wire name. Nullable defaults can be added so absent optional values do not make generated constructors unnecessarily awkward.

Your sample stays on your device because the conversion is performed in JavaScript in the current tab. Use the result as a fast model scaffold, then reconcile dates, identifiers, enums, numeric ranges and optional fields with the documented API contract.

How it works

Create nested Kotlin data classes

Every object shape becomes a data class and nested objects receive names based on their JSON keys. Arrays of objects are merged into a single element model, so properties that only appear on some elements are marked nullable instead of being silently discarded.

Apply Kotlin null safety

Explicit JSON null values and keys missing from some sampled array items produce nullable Kotlin types. With nullable defaults enabled, those constructor parameters also receive = null, which allows kotlinx.serialization to decode payloads where the key is absent.

Add kotlinx.serialization annotations

Serialization mode adds the kotlinx.serialization imports and annotates generated classes with Serializable. SerialName is added when a sanitized Kotlin property differs from the original JSON key, preserving snake_case, kebab-case and other wire formats.

Handle arrays and mixed values

Homogeneous arrays become List<T>, including recursively nested lists. Empty or heterogeneous arrays use Any because a single sample cannot establish one safe element type; replace that fallback when your API documentation provides the real shape.

Frequently asked questions

Do I need kotlinx.serialization in my project?

Only if you leave the serialization option enabled. The annotations require the kotlinx.serialization library and compiler plugin. Disable the option to generate plain Kotlin data classes with no serializer-specific imports.

Why are integers generated as Long?

JSON defines one number syntax and does not declare Int versus Long ranges. Long is a safer default for integral API values. Change a property to Int, BigInteger or a domain type when the contract guarantees a narrower range.

Can the generator recognize dates or enums?

No. A JSON date and an enum case are both ordinary strings in a sample. The generator intentionally emits String; you should replace it with Instant, LocalDate, an enum or another domain type using API knowledge.

Is sensitive JSON uploaded?

No. The parser and Kotlin generator run entirely in your browser, so the payload never leaves your device through this tool.