jsondecode.com logo

JSON to Kotlin Data Class Generator — Free Online Tool

Convert JSON to Kotlin data class definitions with proper types, nullable fields, and kotlinx.serialization annotations using AI. Free, no sign-up.

JSON to BigQuery Schema Converter — Free Online ToolJSON to React Flow Diagram — Convert JSON Online FreeJSON to Go Struct with BSON Tags — Free Online ToolJSON to TypeScript Interface Generator — Free OnlineJSON to YAML Converter — Convert JSON to YAML OnlineJSON to CSV Converter — Export JSON Array to CSV FreeJSON to Python Dataclass Generator — Free Online ToolJSON to SQL INSERT Statement Generator — Free OnlineJSON to Markdown Table Converter — Free Online ToolJSON to XML Converter — Convert JSON to XML Online FreeJSON to HTML Table Converter — Free Online ToolYAML to JSON Converter — Convert YAML to JSON Online FreeXML to JSON Converter — Convert XML to JSON Online FreeJSON to JSON Schema Generator — Free Online ToolJSON to GraphQL Schema Generator — Free Online ToolRuby to JSON Converter — Convert Ruby Hashes to JSON OnlineJSON to C# Class Generator — Free Online ToolJSON to Java Class (POJO) Generator — Free Online ToolJSON to Rust Struct Generator — Free Online ToolJSON to PHP Array Converter — Free Online ToolCSV to JSON Converter — Free Online ToolJSON to Dart Class Generator — Free Online ToolJSON to Swift Struct (Codable) Generator — Free OnlineJSON to Terraform HCL Variables Converter — Free OnlineJSON to Mongoose Schema Generator — Free Online ToolJSON to Prisma Schema Model Generator — Free OnlineJSON to Protocol Buffer (proto3) Generator — Free OnlineJSON to TOML Config Format Converter — Free Online ToolTOML to JSON Converter — Convert TOML to JSON Online FreeJSON to Apache Avro Schema Generator — Free Online ToolJSON to OpenAPI 3.0 Schema Component — Free Online ToolJSON to R Data Frame Code Generator — Free Online ToolJSON to Lua Table Syntax Converter — Free Online ToolJSON to Zod Schema (TypeScript) Generator — Free OnlineJSON to Scala Case Class with Circe Codec — Free OnlineJSON to PowerShell Hashtable Converter — Free Online Tool

JSON to Kotlin Data Class Generator — Free Online Tool

About JSON to Kotlin Data Class Generator — Free Online Tool

This tool converts JSON objects into Kotlin data classes with kotlinx.serialization annotations, automatically inferring types for all fields including nested objects, arrays, and nullable values. Developers use it to eliminate the tedious manual work of writing boilerplate data classes when integrating REST APIs or parsing JSON responses in Android and Kotlin Multiplatform projects.

JSON to Kotlin Type Mapping

JSON TypeExample ValueKotlin TypeNullable Variant
string"hello"StringString?
number (integer)42IntInt?
number (large integer)9876543210LongLong?
number (decimal)3.14DoubleDouble?
booleantrueBooleanBoolean?
nullnullAny?
object{"key": ...}Nested data classNestedClass?
array of strings["a", "b"]List<String>List<String>?
array of objects[{...}, {...}]List<NestedClass>List<NestedClass>?
empty array[]List<Any>List<Any>?

kotlinx.serialization vs Gson vs Moshi — Feature Comparison

Featurekotlinx.serializationGsonMoshi
Kotlin Multiplatform supportYesNoNo
Null safety enforcementYesNoYes
Code generation approachCompiler pluginReflectionCodegen (kapt/ksp)
@SerialName annotationYesNo (@SerializedName)Yes (@Json)
Default values respectedYesPartialYes
Sealed class supportYes (polymorphism)LimitedLimited
Kotlin coroutines integrationNativeManualManual
Android recommended by GoogleYes (2023+)LegacySupported
Gradle plugin requiredYesNoNo (KSP optional)

Frequently Asked Questions

How do I add kotlinx.serialization to my Android project?

Add the Kotlin serialization plugin to your build.gradle: `id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'` in the plugins block, then add the runtime dependency `implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0'`. The compiler plugin is required — without it, the @Serializable annotation will compile but throw a runtime exception because no serializer is generated.

What does @SerialName do in kotlinx.serialization?

@SerialName maps a Kotlin property name to a different JSON key, which is essential when the API uses snake_case (e.g., user_id) but you want idiomatic Kotlin camelCase (e.g., userId). Without @SerialName, the property name in your data class must match the JSON key exactly or deserialization returns null/default values. Example: `@SerialName("user_id") val userId: String`.

Why are some fields generated as nullable (String?) in my Kotlin data class?

Fields are generated as nullable when the JSON sample contains a null value for that key, or when the key is missing in some objects within a JSON array. Kotlin enforces null safety at compile time, so the generator marks any field that could legitimately be absent or null as nullable to prevent NullPointerExceptions at runtime. If you know a field will always be present, you can remove the `?` manually.

Can kotlinx.serialization handle nested JSON objects and arrays?

Yes — nested JSON objects become separate @Serializable data classes that are referenced as property types, and JSON arrays map to List<T> where T is the inferred element type. For deeply nested structures, the generator creates multiple data classes in the same file. kotlinx.serialization handles arbitrary nesting depth as long as all involved classes are annotated with @Serializable.

How do I handle JSON fields with names that are Kotlin reserved keywords?

Use backtick escaping combined with @SerialName: annotate the property with `@SerialName("object")` and name the Kotlin property something idiomatic like `objectData`, or use backticks like `val \`object\`: String` if you must keep the original name. The @SerialName approach is cleaner and more readable. Reserved keywords that commonly appear in JSON include object, class, in, is, val, and return.

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.