JSON to Kotlin
Generate nested Kotlin data classes from a JSON object.
Your input
Runs locally. Your input is never uploaded or saved.
Output
Your result will appear here.
When this tool helps
Draft Kotlin DTOs for an Android API response before wiring Retrofit or another transport. Keep response types in the data layer so changes to the API do not directly reshape your screen state.
How to use this tool
Generate plain Kotlin models without a serialization dependency. Original JSON keys are preserved in comments. Add annotations for your chosen serializer when field names differ, and review numeric ranges.
A worked example
Input
{"id":42,"display-name":"Mira","active":true,"profile":{"city":"Pune"}}Expected result
// Plain Kotlin models; no serialization library required.
// JSON key comments preserve original names. Add serializer annotations before decoding JSON.
// Review nullability and numeric ranges against your API schema.
data class Account(
// JSON key: "id"
val id: Long,
// JSON key: "display-name"
val display_name: String,
// JSON key: "active"
val active: Boolean,
// JSON key: "profile"
val profile: AccountProfile
)
data class AccountProfile(
// JSON key: "city"
val city: String
)Set the root name to Account. Whole numbers become Long, booleans become Boolean, and the nested profile becomes another class. Comments preserve the JSON keys, including display-name, which cannot be used unchanged as an ordinary property identifier.
Edge cases and limitations
- The output is a set of classes, not a JSON decoder. Add the annotations and adapter required by your chosen serialization library.
- JSON key comments do not configure field mapping. Map display_name to display-name explicitly in your serializer.
- A single non-null sample does not prove a field is required. Review nullability, defaults, and absent fields against the API contract.
- Empty and mixed-shape lists fall back to List<Any?>. Large integers may already have lost precision in the browser before a Long is generated.
Use the result in your app
Add a serializer-backed fixture test that decodes the original response and checks every mapped property. Include a response with an omitted optional field. Keep this test separate from repository network tests.
Keep your workflow private
This utility processes input only in this tab. It does not upload or persist pasted content. Review generated output before using it in a production application.
Need a complete starter? Generate a Flutter project →