Omnikit
DevFilesMoneyAll tools
Ctrl K
Dev toolsFile toolsMoney calculatorsAll tools
HomeDeveloper toolsJSON to Kotlin Data Class Converter
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский

JSON to Kotlin Data Class Converter

dev

Turn a JSON sample into Kotlin data classes for kotlinx.serialization, Gson or Moshi

Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.

Paste a JSON sample and get Kotlin data classes for kotlinx.serialization, Gson or Moshi. Whole numbers become Int, Long past 2,147,483,647, any decimal makes a property Double, a null value makes it nullable, and a key missing from some objects becomes T? = null so all 3 libraries decode it.

Next:
  • JSON to Java Class Converter Turn a JSON sample into Java POJOs, records or Lombok classes annotated for Jackson
  • JSON Formatter & Validator Format, validate, minify and sort JSON with exact error positions

How to convert JSON to a Kotlin data class

1

Paste a JSON sample, such as an API response, into the left box.

2

The Kotlin data classes appear as you type, one per object, with camelCase properties and an annotation wherever a key differs.

3

Choose kotlinx.serialization, Gson or Moshi, var instead of val if you need it, and the root class name.

4

Press Copy, or Download to save Models.kt.

About JSON to Kotlin Data Class Converter

Kotlin reads JSON into data classes, and each object needs a class whose properties have the right types, the right nullability and a way back to their keys. This converter writes those classes from a sample, so a long API response becomes Kotlin in one paste.

How types are chosen.

JSON value Kotlin type
"text" String
true / false Boolean
42 (whole numbers only) Int, or Long beyond 32 bits
4.5 (any decimal seen) Double
null, and also a type String?, Int?
only null, or mixed kinds JsonElement? or Any?
[ ... ] List<...>
{ } empty JsonObject or Map<String, Any?>
{ ... } a data class of its own

Missing keys. All the objects of an array are merged into one class. A key that some of them leave out becomes nullable with null as its default, because kotlinx.serialization and Moshi treat a missing key without a default as an error. kotlinx.serialization also rejects keys it has no property for, so every key of the sample gets one.

Names. Properties are lowerCamelCase. Where that changes the key, as user_name to userName, the property carries @SerialName, @SerializedName or @Json(name = ...), depending on the library. Keywords such as class are written in backticks. Annotation strings escape the dollar sign, since Kotlin would read it as a template.

Options. var instead of val gives mutable properties. An empty object becomes a plain class, because a data class needs at least one property. The root class is called Root unless you name it.

Every output was checked by reading the Kotlin back and decoding 9 samples with kotlinx.serialization's default rules. Nothing you paste leaves the browser.

Frequently asked questions

How do I convert JSON to a Kotlin data class?

Paste a JSON sample into the converter and the data classes appear beside it, one per object. With kotlinx.serialization, add the plugin and decode with Json.decodeFromString<Root>(text); with Gson use Gson().fromJson(text, Root::class.java); with Moshi build an adapter for Root.

Why do some properties end with = null?

A key that some objects of an array leave out gets a nullable type and null as its default. kotlinx.serialization and Moshi both refuse a missing key unless the property has a default, so the default is what lets every object of the sample decode.

Which library should I choose?

kotlinx.serialization is Kotlin's own, works on every Kotlin platform and checks types at compile time. Moshi with codegen suits Android projects that already use Retrofit and Okio. Gson is the oldest and needs no setup, but it ignores Kotlin's null safety and default values when it creates objects.

How are keys like user_name or class handled?

Properties are lowerCamelCase, so user_name becomes userName with @SerialName, @SerializedName or @Json(name = ...) keeping the original key. A key that is a Kotlin keyword, such as class or object, is written in backticks, which keeps the key as the property's real name.

How are numbers typed in Kotlin?

Whole numbers become Int, or Long when a value is beyond 2,147,483,647, and a field becomes Double as soon as any sample value has a decimal part. Values of different kinds become JsonElement? with kotlinx.serialization, or Any? with Gson and Moshi.

Is my JSON uploaded?

No. The conversion runs in your browser with no request to any server, and the JSON is not stored, so API responses holding tokens or personal data stay on your device. Close the tab and nothing remains.

Sources

  • Kotlin documentation, keywords and operatorsHard keywords that need backticks as names
  • Kotlin documentation, coding conventions: naming rulesUpperCamelCase classes, lowerCamelCase properties
  • kotlinx.serialization guide, basic serialization@SerialName, optional properties need defaults, unknown keys are errors
  • Moshi README, Kotlin codegen@JsonClass(generateAdapter = true) and @Json(name = ...)

Last verified 16 October 2026.

Rates and rules change; check the source before you rely on a figure.

Still stuck? Ask about JSON to Kotlin Data Class Converter and anybody who knows can answer. No account needed.

Common uses

  • JSON to Kotlin for GsonPaste JSON and get Kotlin data classes with @SerializedName for Gson

Same job, other tools: Image to Base64 – Get a data URI for any image, ready for CSS or HTML · TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.

Related tools

All developer tools
Base64 Encode & DecodeText and files to Base64 and back, with URL-safe mode and image previewUnix Timestamp ConverterUnix timestamps to dates and dates to timestamps, in any time zoneJSON to TypeScriptGenerate TypeScript interfaces or types from a JSON sampleCSV to JSONConvert CSV to JSON and JSON to CSV, with a table previewYAML to JSONConvert YAML to JSON and JSON to YAML, with anchors resolvedURL Encoder / DecoderPercent-encode or decode text and URLs, and see every part of a linkColor ConverterHEX, RGB, HSL, HWB, OKLCH and CMYK in both directions, with a contrast checkNumber Base ConverterBinary, octal, decimal, hex and any base to 36, exact at any size, with two's complement
Was this tool helpful?
Omnikit

Small jobs, done in your browser. Free, fast and private. Files are never uploaded.

Files

  • Compress Image
  • Image to PDF
  • Merge PDF
  • Compress PDF
  • PDF to Word
  • Word to PDF

Dev

  • JSON Formatter & Validator
  • Base64 Encode & Decode
  • JWT Decoder, Verifier & Encoder
  • Password Generator
  • UUID Generator
  • Unix Timestamp Converter

Money

  • SIP Calculator
  • EMI Calculator
  • GST Calculator
  • FD Calculator
  • PPF Calculator
  • Lumpsum Calculator
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский
GuidesQuestionsAboutHow we checkLaw library (beta)PrivacyTermsDisclosureContactMore: Exam practice (UGC NET Paper 1)Runs in your browser. Nothing is uploaded. © 2026 Omnikit (theomnikit.com)