JSON to Kotlin

Paste JSON and instantly get matching Kotlin data class declarations with nested classes and nullable-safe types.

Use the JSON to Kotlin

Input JSON

Kotlin Output

Paste JSON and click Generate

Copied!

Summary

JSON to Kotlin reads a JSON value and generates matching Kotlin data class declarations, including separate classes for nested objects and List types for arrays. When a field is missing from some entries in an array of objects, or the field can hold a null value, the generated property is typed nullable with a `= null` default so the class stays safe to construct from partial data. Field names are converted to camelCase and the original JSON key is noted in a comment whenever it differs from the Kotlin property name.

How it works

  1. Paste or type JSON into the input panel, or load a sample.
  2. Set a root class name (defaults to RootObject).
  3. Click Generate to parse the JSON and build Kotlin data classes.
  4. Nested objects become their own named data classes; arrays of objects are scanned across all items to detect optional fields.
  5. Fields that are missing from some items, or that hold null, become nullable properties with a null default.
  6. Click Copy to copy the Kotlin code to your clipboard.

Use cases

  • Scaffold data classes for a REST API response before writing a Retrofit or Ktor client.
  • Turn a sample config file into a typed Kotlin settings class.
  • Generate a starting model for kotlinx.serialization or Moshi without typing every field by hand.
  • Document a third-party API response shape as Kotlin types.
  • Check which fields are optional before writing null-handling logic by hand.
  • Speed up adding an Android or backend Kotlin model from sample JSON.

Frequently Asked Questions

Last updated: 2026-07-13 · Reviewed by Nham Vu