JSON Parser

JSON to Kotlin Data Class Converter Online

Paste any JSON and get ready-to-use Kotlin types in one click. Nested objects, arrays, optional fields and awkward key names are handled for you, and everything runs in your browser, so API responses and sample payloads are never uploaded.

How to convert JSON to Kotlin

  1. Paste your JSON, or click Upload to load a file. Use a sample that includes every field, since the types are inferred from it.
  2. Set the Root class name if you want something other than Root.
  3. Review the output on the right and click Copy.

Example

JSON input

{
  "id": 1,
  "name": "Alice",
  "active": true,
  "score": 98.5,
  "tags": ["admin"],
  "address": { "city": "New York" }
}

Kotlin output

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class Root(
    val id: Long,
    val name: String,
    val active: Boolean,
    val score: Double,
    val tags: List<String>,
    val address: Address
)

@Serializable
data class Address(
    val city: String
)

JSON to Kotlin type mapping

JSONKotlin
stringString
whole numberLong
decimal numberDouble
booleanBoolean
arrayList<T>
objecta data class
null / unknownAny

Naming and structure

Properties are camelCase. Classes are annotated @Serializable for kotlinx.serialization, and keys that differ from the property name get @SerialName("key").

  • Fields that are null or missing in some items become nullable with a default of null, so decoding doesn't fail when the key is absent.
  • Using Gson or Moshi? Swap @SerialName for @SerializedName or @Json(name = ...).
  • When an array contains objects, their fields are merged: a field missing from some items is treated as optional, and a field that is a whole number in one item and a decimal in another becomes a decimal.
  • The top-level JSON can be an object or an array of objects.

Using the generated types

val root = Json.decodeFromString<Root>(jsonString)

Related tools

Describe the same data with the JSON Schema generator, get TypeScript interfaces, create a SQL table, fix broken input with JSON Repair, or compare payloads with JSON Diff.

Frequently asked questions

How do I convert JSON to Kotlin data classes?
Paste your JSON and copy the output. Objects become @Serializable data classes, arrays become List<T>, whole numbers become Long and decimals become Double.
Which JSON library does the output use?
kotlinx.serialization. Keys that are not valid Kotlin property names get @SerialName("original-key"). If you use Gson or Moshi, replace @SerialName with @SerializedName or @Json(name = ...).
How are nullable fields represented?
Fields that are null or absent in some array items become nullable types with a default of null (val note: String? = null), so decoding does not fail when the key is missing. Everything runs in your browser — your JSON is never uploaded to a server.
Handles JSON files up to 20MB smoothly