JSON to Kotlin
Generate idiomatic Kotlin data classes with clean property names and null-safety directly in your browser.
- Runs in your browser
- Free, no signup
data class Root(
val id: Int,
val name: String,
val email: String,
val isAdmin: Boolean, // JSON key: "is_admin"
val roles: List<String>,
val profile: Profile
)
data class Profile(
val bio: String,
val reputation: Int
)
Your files are processed locally in your browser and are not uploaded to our server.
Building Android applications or Kotlin multiplatform backend services requires strongly typed models for network communication. This tool instantly converts raw JSON payloads into clean, idiomatic Kotlin data classes.
Properties are mapped to immutable val declarations, lists become List<T>, and fields that hold null are marked with Kotlin's null-safety operator (T?). Keys that deviate from Kotlin identifier conventions (such as snake_case or kebab-case) are automatically camelCased and accompanied by comments noting their original JSON key.
How to use this tool
- Paste your JSON payload into the editor or click "Load Sample" to load a representative model.
- Provide an optional root model name (e.g., User or Response) and an optional package declaration.
- Inspect the generated Kotlin data classes in real time on the right-hand panel.
- Click "Copy Code" to copy to your clipboard, or "Download .kt" to download a Kotlin source file for your project.
Idiomatic Kotlin Data Class Generation
Kotlin data classes automatically provide equals(), hashCode(), toString(), copy(), and componentN() functions. The generator formats each JSON object as a concise data class declaration with clean indentation and val parameters.
Nested JSON structures are extracted into standalone, reusable data classes rather than deeply nested anonymous types, creating clean architectures suitable for Android and Spring Boot projects.
First-Class Null Safety and Type Mapping
Kotlin prevents NullPointerExceptions through its strict type system. When a field in your JSON contains null, the generator flags it as nullable (such as String?, Int?, or Double?).
Non-null values remain strict non-nullable types, giving you compile-time certainty and reducing redundant defensive checks in your codebase.
Automatic camelCase Formatting and Reserved Keyword Protection
JSON APIs frequently use snake_case keys (such as "created_at" or "user_id"). Kotlin style guidelines call for camelCase identifiers. The generator automatically converts keys into clean camelCase (e.g., "createdAt", "userId") and documents the original JSON key name.
If a JSON key coincides with a Kotlin reserved keyword (such as "class", "val", "fun", or "is"), it is safely sanitized to avoid compiler syntax errors.
Client-Side Privacy for API Payloads
Never risk exposing sensitive internal API structures or user credentials to third-party conversion servers. ToolDuck processes everything directly inside your browser tab without making network requests.
Frequently asked questions
Can I specify a package name for the generated Kotlin classes?
Yes. Enter your package name (e.g. com.example.models) in the package field, and it will be prepended to the generated Kotlin code automatically.
How does the generator handle JSON arrays in Kotlin?
Arrays of primitive types are typed as List<String>, List<Int>, or List<Double>. Arrays of objects are typed as List<ModelName>, with the underlying object model defined as its own data class.
Can I use the generated code with Kotlinx Serialization or Moshi?
Yes. The generated data classes follow standard Kotlin conventions. The original JSON keys are documented alongside changed property names, making it easy to add @SerialName or @Json annotations.
Is my JSON uploaded anywhere during conversion?
No. All parsing and Kotlin code generation is performed locally in your web browser. Nothing is sent to our servers.