JSON to Kotlin Data Class Generator
Generate Kotlin @Serializable data classes with type annotations from sample JSON.
- 100% free
- Private in browser
- No signup
- No watermarks
Kotlin Data Classes (1)
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerialName
@Serializable
data class UserData(
@SerialName("user_id")
val userId: Long,
@SerialName("full_name")
val fullName: String,
val premium: Boolean
)About JSON to Kotlin Data Class Generator
The JSON to Kotlin Data Class Converter generates Kotlin data classes from a sample JSON payload. Paste an API response, set a root class name, and the tool writes camelCase val properties, marks each class @Serializable, and adds @SerialName wherever the property name differs from the JSON key. Whole numbers become Long, decimals become Double, and arrays become List<T>. The output targets kotlinx.serialization, and types are inferred from the one sample you paste, so review nullable fields.
How to use JSON to Kotlin Data Class Generator
- Enter a root class name, such as UserData.
- Paste your sample JSON into the Input JSON box.
- Review the properties and the class count in the Kotlin Data Classes panel.
- Click Copy Kotlin Code and paste the classes into a .kt file.
Key features
- @Serializable data classes with val constructor properties
- @SerialName added only when the camelCase name differs from the key
- Maps whole numbers to Long, decimals to Double, and booleans to Boolean
- Creates a separate data class for each nested object
- Types arrays as List<T> based on their first element
- Includes the kotlinx.serialization imports
Frequently asked questions
- How do I convert JSON to a Kotlin data class?
- Paste your JSON into the Input JSON box, set a root class name, and the data classes are generated instantly. Click Copy Kotlin Code to copy them into your project.
- Does the output work with Gson or Moshi?
- Not directly. The classes use kotlinx.serialization annotations. For Gson, remove @Serializable and replace @SerialName("key") with @SerializedName("key"); for Moshi, use @Json(name = "key").
- When is @SerialName added to a property?
- Only when the camelCase property name is different from the JSON key. A key like user_id becomes val userId with @SerialName("user_id"), while a key like premium needs no annotation.
- How are null values and empty arrays typed?
- A null value becomes Any? and an empty array becomes List<Any>. kotlinx.serialization cannot handle Any without a custom serializer, so replace these with a real type such as String? or List<String> before you compile.
- How do I make a generated property optional?
- Add a nullable type and a default value yourself, for example val nickname: String? = null. The generator makes every property required and non-null, so decoding fails if a key is missing from the response.
Related In-Depth Guides
Learn practical workflows, real-world examples, and expert tips in our comprehensive guides:
Password Entropy Explained: How Bits Measure Brute-Force Cracking Time
Understand Shannon entropy in passwords, character pool combinations, and how many seconds, years, or millennia it takes GPUs to crack modern passphrases.
How to Convert Docker Run Commands to Docker Compose YAML Files
A comprehensive developer guide to transforming complex docker run commands into clean, maintainable docker-compose.yml files.
Web Accessibility & Color Contrast (WCAG 2.1): How to Design AA & AAA Palettes
A practical guide to color contrast ratios, accessibility compliance, WCAG 2.1 AA/AAA standards, and building accessible UI palettes.
Rate this tool
Be the first to rate — helps others and improves this page.