JSON to Kotlin Data Class Converter
Paste a JSON object and get ready to use Kotlin data classes with a type inferred for every field. Whole numbers become Int, decimals Double, arrays List, and each nested object turns into its own class named in PascalCase after its key. It runs entirely in your browser, so nothing you paste is sent to a server.
How to convert JSON to Kotlin data classes
- Paste a JSON object into the JSON object box, or click Load sample to see the format.
- Set the Root class name field if you want something other than Root.
- Watch the Kotlin data classes appear in the output box as you type.
- Fix any error shown in red, such as invalid JSON or a non-object root.
- Click Copy and paste the declarations straight into your Kotlin project.
Examples
Mixed field types with a nested object
{"id":1,"name":"Ada","active":true,"score":3.5,"tags":["dev","math"],"address":{"city":"Oslo","zip":null}}data class Root(
val id: Int,
val name: String,
val active: Boolean,
val score: Double,
val tags: List<String>,
val address: Address
)
data class Address(
val city: String,
val zip: Any?
)Array of objects becomes List of a generated class
{"items":[{"sku":"A1","qty":2}]}data class Root(
val items: List<Items>
)
data class Items(
val sku: String,
val qty: Int
)Custom root class name
{"userName":"ada","age":30}data class Account(
val userName: String,
val age: Int
)Frequently asked questions
Is my JSON uploaded anywhere?
No. The conversion runs entirely in your browser with JavaScript, so the JSON you paste never leaves your device and nothing is stored on a server.
How are field types inferred?
Whole numbers become Int, fractional numbers Double, text String, true or false Boolean, arrays List of the first item's type, nested objects their own class, and JSON null the nullable Any?.
How are nested objects handled?
Each nested object becomes its own data class named in PascalCase after the key that held it, and the parent class references it by that type name. Parents are always printed before the classes they contain.
How are arrays typed?
A list takes the type of its first element, so a string array becomes List<String> and an array of objects becomes List of a generated class. An empty array cannot be inspected, so it falls back to List<Any?>.
Are property names changed to match Kotlin style?
No. Keys are kept exactly as written, so a JSON key of user_name stays val user_name. If your API uses snake_case, add kotlinx.serialization and a @SerialName annotation to map it to a camelCase property yourself.
Does it add @Serializable or Gson annotations?
No. The output is plain Kotlin data classes with no annotations or imports, so you can drop them in and add whichever serialization library you prefer.
What happens with a null value?
A null value is typed as the nullable Any?, since a concrete type cannot be inferred from null alone. If other responses fill that field, widen the type by hand, for example to String?.
Why are large numbers still typed as Int?
Any whole number is inferred as Int, so a value larger than a 32 bit Int can overflow. If a field holds big ids or timestamps, change its type to Long after pasting.
Why must the input be a JSON object?
Data classes model named fields, so the converter needs an object at the root. A bare array, string or number has no field names and cannot become a data class, so it reports an error.
Learn more
- Turning JSON API responses into Kotlin data classes
Why data classes fit JSON payloads, how types are guessed from one sample, and how to add kotlinx.serialization and correct nullability.
Related tools
JSON to PHP Array
Convert JSON to a PHP array online. Paste JSON and get a clean array() or short [] literal with correct nesting, quoting and types. Runs in your browser.
JSON to Python Dict
Convert JSON to a Python dict online. Paste JSON and get a valid dict and list literal with True, False, None and proper quoting. Runs in your browser.
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
Air Fryer Converter
Convert any conventional oven recipe to air fryer settings. Lower the temperature by 25 F and cut the cook time by about 20 percent automatically.
Baker's Percentage Calculator
Turn a bread formula into grams with baker's percentages. Flour is 100 percent, enter water, salt and yeast percents to get weights and hydration.
Baking Pan Converter
Swap one baking pan for another and scale the batter to fit. Compares pan areas for round, square and rectangular pans and gives a batter scale factor.