JSON to Kotlin Data Class
Generate nested Kotlin data classes with nullable defaults and kotlinx or Jackson annotations
Optional fields are inferred from missing and null values across object samples. Mixed types fall back to a generic type; review the result against the real API contract.
Generated Kotlin data classes will appear here.
About this tool
JSON to Kotlin Data Class turns a JSON object or representative array into nested data classes. Primitive samples map to String, Long, Double, and Boolean; arrays become List values, nested objects become named classes, and mixed values fall back to Any. Fields missing or null in any sample become nullable and can receive a default null value. Choose kotlinx.serialization, Jackson, or no annotations; SerialName or JsonProperty is emitted where Kotlin identifier normalization changes a wire key. The output does not infer Instant, BigDecimal, sealed hierarchies, enums, default business values, Android Parcelable, or framework-specific adapters, so compile it with the selected serialization library and real fixtures.
Scenario Recipes
Prepare mobile API response models
Goal: Capture observed nullability before wiring a serialization library
- Paste an array containing normal records plus examples with missing optional fields.
- Choose kotlinx.serialization or Jackson, enable null defaults, and set the response model name.
- Generate classes, replace Any and generic strings with domain types, then decode fixture responses in unit tests.
Result: A nested Kotlin model draft with observed nullability and explicit wire-name annotations.
Frequently Asked Questions
Can I choose kotlinx.serialization or Jackson?
Yes. The annotation selector emits imports and name annotations for either library, or no annotations.
How are optional properties generated?
Missing or null sample fields become nullable types and can default to null.
Are nested JSON objects separate data classes?
Yes. The generator derives deterministic PascalCase class names from property names.
What happens to mixed field types?
They fall back to Any so the output does not pretend an unreliable concrete type is safe.
Does it generate Android Parcelable or Room annotations?
No. Those are platform and persistence decisions outside JSON shape inference.
Is sample JSON uploaded?
No. Parsing, inference, annotation selection, and Kotlin generation happen locally.
Keep browsing