JSON to Kotlin Data Class Converter
Paste a JSON sample to instantly generate matching Kotlin data classes with nullable properties inferred automatically. Free online developer tool.
Paste JSON
Kotlin Data Classes
Kotlin data class definitions will appear here...
Free JSON to Kotlin Data Class Converter
Paste a JSON sample to instantly generate matching Kotlin data class declarations, with nullable properties and default values inferred straight from your data.
How to Use It
Paste any JSON object or array, or click "Load Example." The tool infers a type shape and emits one data class per object level, with camelCase constructor properties, nested objects pulled out into their own named data class, List<T> for arrays, and a nullable type (Type?) with a = null default for any property that's optional or nullable in your sample.
Example
Given {"name": "Ann", "age": 30, "tags": ["a","b"], "address": {"city": "NYC", "zip": null}}, the tool emits data class RootAddress(val city: String, val zip: String? = null) and aRoot data class referencing it, with tags: List<String>.
Common Use Cases
- Modeling API responses for Retrofit or Ktor clients in an Android or Kotlin backend project.
- Generating immutable data classes for use with kotlinx.serialization or Moshi.
- Bootstrapping types quickly from a sample payload instead of writing them by hand.
FAQs
Why do some properties get a default value of null?
Giving optional or nullable properties a = null default lets you construct instances of the data class without supplying every field, which mirrors how the property might legitimately be absent from the JSON.
Does this work with kotlinx.serialization?
The generated data classes are plain Kotlin and map cleanly onto kotlinx.serialization or Moshi models — you may want to add @Serializable or @JsonClass annotations depending on which library you use.
Is my JSON uploaded anywhere?
No — parsing and code generation happen entirely client-side in your browser. Nothing you paste is sent to a server.
