How to use the JSON to Kotlin Data Class
Generate Kotlin data classes in seconds:
1
Paste your JSON
Paste any JSON object from your API response, Postman, or API docs.
2
Choose annotation library
Select Gson (@SerializedName), Moshi (@Json), or None for a plain data class.
3
Set class name
Enter the root data class name — nested class names are inferred automatically.
4
Copy into Android Studio
Copy the output and paste the generated data classes directly into your Kotlin project.
When to use this tool
Use this tool whenever you need Kotlin models from JSON:
- →Building an Android or KMM app that consumes a REST API via Retrofit and needs Kotlin data classes
- →Scaffolding response models quickly from API documentation or Postman JSON examples
- →Migrating an Android project from Java POJOs to idiomatic Kotlin data classes
- →Working with Gson or Moshi and needing @SerializedName / @Json annotations generated automatically
- →Handling snake_case API responses that need to be mapped to camelCase Kotlin properties
Frequently asked questions
Q:Does it support Gson and Moshi annotations?
Yes — toggle between Gson (@SerializedName) and Moshi (@Json) annotations from the toolbar. The correct import statement is included automatically. Annotations are only added when the property name differs from the JSON key (e.g. snake_case keys).
Q:Are nested objects and arrays supported?
Yes. Nested JSON objects are converted into separate Kotlin data classes and referenced by the parent class. JSON arrays are typed as List<T> — arrays of objects generate a dedicated data class for the item type.
Q:Does it handle snake_case and kebab-case JSON keys?
Yes. JSON keys in snake_case (first_name) or kebab-case (first-name) are automatically converted to idiomatic camelCase Kotlin property names (firstName). The original key name is preserved in the @SerializedName or @Json annotation so serialization still works correctly.
Q:How are nullable types handled?
Fields whose value is null in the sample JSON are typed as String? (nullable). For non-null fields, the type is inferred from the value. Review generated classes and add ? to any fields that may be absent in real API responses before shipping to production.
Q:Does it support kotlinx.serialization?
kotlinx.serialization (@Serializable and @SerialName) is on our roadmap. Currently Gson and Moshi are fully supported. For now, kotlinx.serialization users can use the 'None' option and add @Serializable manually.
Q:Can I use this for Kotlin Multiplatform (KMM/KMP) projects?
Yes. The generated data classes are plain Kotlin with no Android-specific dependencies. They work in any Kotlin target — Android, JVM, iOS via KMM, or server-side Kotlin.