Zero Signup ToolsFree browser tools

Developer Tools

JSON to Kotlin Data Class Converter

Convert JSON to Kotlin data classes in your browser. kotlinx.serialization, Gson, or Moshi annotations, nullable types, Long or Int, and tidy property naming.

0 chars

Output options

Live preview updates with every change. All parsing and inference run in your browser; the JSON you paste is not uploaded.

Used as the name of the top-level data class. Normalised to a valid PascalCase Kotlin identifier automatically.

Lowercased and stripped of invalid characters automatically. Reverse-domain style is conventional in JVM packages.

Declaration style

data class gives you componentN(), copy(), equals, hashCode, and toString for free. Plain class only emits the constructor and properties, useful when you want to extend a base class or define your own equality semantics.

Serializer / annotation style

kotlinx.serialization marks the class with @Serializable and uses @SerialName, the standard choice for Kotlin Multiplatform and Ktor projects. Gson uses @SerializedName, the long-time Android default. Moshi uses @JsonClass(generateAdapter = true) plus @Json(name = ...), the current Square recommendation paired with Retrofit. Annotations appear only when the JSON key differs from the Kotlin property name (snake_case, kebab-case, leading digits, reserved words).

Integer type

Long is the safer default for IDs, Unix epoch timestamps, and any numeric value that may exceed 2,147,483,647. Int saves a few bytes per record when you know the values fit.

Collection type for arrays

List is read-only and matches DTO conventions. Choose MutableList when you intend to add or remove entries in place; kotlinx.serialization, Gson, and Moshi all deserialize cleanly into either type.

Indent

The official Kotlin style guide defaults to 4 spaces. Android Studio and IntelliJ both follow the same default.

How to use

  1. Paste a JSON value into the input on the left, or click Load sample JSON to see a worked example with nested objects, arrays, a null field, and snake_case keys.
  2. Pick a declaration style. data class is the standard Kotlin DTO container with copy, componentN, equals, hashCode, and toString built in. Plain class skips those generated members when you need a custom equality contract or a base class.
  3. Choose a serializer annotation style. kotlinx.serialization adds @Serializable and uses @SerialName for renamed keys. Gson uses @SerializedName. Moshi uses @JsonClass(generateAdapter = true) plus @Json(name = ...). Pick No annotations for a pure data class.
  4. Set the integer type (Long for IDs and Unix timestamps, Int when you want compact values). Pick List or MutableList for arrays. Keep Default nullable properties to null on so missing keys deserialize without throwing.
  5. Optionally add the package statement, toggle 2 or 4 space indentation, sort properties A to Z, switch val to var if you need mutation, and turn on Separate file per class when each class will live in its own .kt file.
  6. Click Copy Kotlin to put the full output on your clipboard, ready to paste into Android Studio or IntelliJ IDEA.

About this tool

JSON to Kotlin Data Class Converter turns any JSON value into idiomatic Kotlin type declarations entirely in your browser. Paste an API response, a config snippet, a webhook payload, or a copied object literal, and the tool parses it with the browser's native JSON parser, walks the resulting tree, and emits one named type per object shape with property names and types that match Kotlin conventions. Choose between two declaration styles to fit your codebase: a modern data class with val properties in the primary constructor (the standard Kotlin DTO container that gives you componentN, copy, equals, hashCode, and toString for free) or a plain class when you want to extend a base class or define your own equality semantics. Property names are camelCased per the official Kotlin style guide, type names are PascalCased, and common initialisms (Id, Url, Api, Http, Https, Ip, Json, Uuid, Db, Sdk, Ssl, Tls) are normalised so user_id becomes userId, api_url becomes apiUrl, and tag_ids becomes tagIds without manual edits. Whenever a JSON key does not round-trip to the Kotlin property name verbatim (snake_case, kebab-case, leading digits, reserved words), the tool emits the right serialiser annotation automatically: @SerialName("original_key") for kotlinx.serialization paired with a class-level @Serializable (the standard choice for Kotlin Multiplatform, Ktor, and modern server-side Kotlin), @SerializedName("original_key") for Gson (the long-time Android default and still ubiquitous in Retrofit projects), or @Json(name = "original_key") for Moshi paired with @JsonClass(generateAdapter = true) (the current Square recommendation that pairs cleanly with Retrofit and Moshi codegen). Numbers split into Long or Int for integers and Double for anything with a fractional part, with the integer preference exposed as a toggle so you can match Unix epoch timestamps, Twitter snowflake IDs, and Stripe object IDs without manual edits. Nullability uses Kotlin's first-class nullable types: a trailing question mark is appended whenever a key is missing in some samples or whenever the JSON ever saw a null for that key, and an optional Default nullable properties to null switch adds an = null default so Moshi and kotlinx.serialization can tolerate missing keys without throwing. Collection inference picks List or MutableList based on the toggle, and the val versus var choice is respected so you can produce immutable DTOs (the recommended default) or mutable types when you need to mutate fields in place. Output options cover package declaration (kept lowercase and stripped of invalid characters), 2 or 4 space indentation, original JSON insertion order versus alphabetic property sorting, and a separate-file mode that emits each class with its own package and import statements ready to paste into individual .kt files; the single-file default places every class side by side at the top level, which is the idiomatic Kotlin convention. Useful for typing Retrofit and Ktor response bodies, generating DTOs for Android view layers, modelling third-party webhook payloads, scaffolding kotlinx.serialization models for Kotlin Multiplatform, prepping Moshi-friendly DTOs for new Square stacks, and saving the boilerplate that every pull request adding a new endpoint would otherwise need. Parsing, schema inference, and code generation run locally on your device, so the JSON you paste here never leaves your browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools