>_devtools

JSON to Kotlin Data Class Converter

Generate Kotlin data classes from a JSON sample for kotlinx.serialization, Jackson, or Klaxon.

What this does

Generates Kotlin data class declarations from a JSON sample. Each nested object gets its own class, properties use val, and optional values are nullable with anull default so the classes can be constructed without them.

Example

Input

{
  "id": 42,
  "name": "Ada",
  "verified": true,
  "tags": [
    "admin",
    "dev"
  ],
  "orders": [
    {
      "sku": "A1",
      "qty": 2
    },
    {
      "sku": "B2",
      "qty": 1,
      "note": "gift"
    }
  ]
}

Output with default options

package com.example

data class Root (
    val id: Long,
    val name: String,
    val verified: Boolean,
    val tags: List<String>,
    val orders: List<Order>
)

data class Order (
    val sku: String,
    val qty: Long,
    val note: String? = null
)

How values are mapped

  • Whole numbers become Long, other numbers Double, strings String, booleans Boolean.
  • Arrays become List<T>; a field missing from some objects becomes T? = null.
  • ISO 8601 timestamps become java.time.OffsetDateTime when date detection is on; an always-null value becomes Any?.
  • Arrays with mixed element types become a sealed class with one subclass per type.

Options

Set the package and root class name, and pick the serialization library:kotlinx.serialization, Jackson, or Klaxon. The library only matters when Types only is turned off, in which case the output includes that library's annotations (for example @JsonProperty for Jackson) and to/from JSON helpers.

Things to know

Property names are converted to lowerCamelCase, so user_id becomesuserId; the serialization annotations preserve the original JSON key. Use several objects in an array so optional fields are detected.

Privacy

Generation runs in a Web Worker in your browser. The JSON is never uploaded.