Developer Tools

JSON to Kotlin Data Class Converter

Paste any JSON and get a @Serializable Kotlin data class ready for kotlinx.serialization. Keys that aren't valid Kotlin identifiers are mapped with @SerialName — everything runs entirely in your browser.

100% in-browserNo signupFree forever

Result

What makes this tool different

kotlinx.serialization ready

Output is annotated with @Serializable, and @SerialName maps keys that aren't valid Kotlin identifiers (like user-id or @type) so decoding stays lossless.

Nested data classes

Every nested object becomes its own data class, and arrays become typed List<Model>.

Sensible defaults

Nullable and optional fields get safe default values so deserialization never crashes.

100% in-browser privacy

Code generation runs locally. Your JSON never touches a server.

About this tool

JSON to Kotlin Data Class Converter: everything you need to know

Android and backend teams that write Kotlin know the drill: every API response needs a data class that matches the JSON shape. Writing these by hand is repetitive, and a single mismatched key or missing nullable annotation causes a runtime crash. A JSON to Kotlin data class converter eliminates the error-prone manual step.

OpenToolLab's converter generates data classes annotated for kotlinx.serialization — the standard Kotlin serialization library. Each class is marked @Serializable, keys that aren't valid Kotlin identifiers are mapped with @SerialName, and every property is typed from the JSON sample: String, Int, Double, Boolean, List<T>, and nested data classes.

Nullable and optional fields receive safe defaults, so deserialization never throws because a key is missing or null. This matches the defensive pattern Kotlin developers rely on and keeps the generated code production-ready without edits.

Because the generator is shared across languages, the same JSON can produce Kotlin data classes, Dart models, Swift Codable structs, or TypeScript interfaces from one window. Teams maintaining Android, iOS, Flutter, and web clients convert once and copy the output for each stack.

Privacy is guaranteed. All code generation happens locally in your browser — your API responses and schemas never leave your device. Open the DevTools Network tab while converting and you will see zero network requests.

The generated code follows kotlinx.serialization conventions exactly as documented, so it fits cleanly into a Gradle project with the kotlinx-serialization plugin enabled. Add the @Serializable classes to your models package, decode responses with Json { ignoreUnknownKeys = true }, and move on.

Use it when onboarding a new API, regenerating models after a backend change, or converting a Swagger/OpenAPI example into Kotlin types. Paste the sample, generate, and your models stay in sync with the data contract without manual transcription.

OpenToolLab is a completely free JSON to Kotlin data class converter with no signup and no limits. Paste, generate, and copy — privately and instantly, entirely in your browser.

FAQ

JSON to Kotlin Data Class Converter — frequently asked questions

How can I convert JSON to Kotlin data classes?

Paste your JSON into OpenToolLab's JSON to Kotlin converter and click Generate code. The tool emits @Serializable data classes with @SerialName where needed, typed properties, defaults, and nested classes ready for kotlinx.serialization.

How can I use JSON in Kotlin?

Add kotlinx.serialization to your project, decode with Json { ignoreUnknownKeys = true }.decodeFromString<MyModel>(json), and use the generated data class. This converter generates the @Serializable model for you.

How to convert JSON to Java class?

For Java, use Gson or Jackson with a JSON to Java tool. OpenToolLab focuses on Kotlin data classes, which are the idiomatic choice for modern Android development; switch this converter's language tab if you need Dart, TypeScript, or Swift instead.

How to convert from JSON to object?

Decode the JSON string with kotlinx.serialization: Json.decodeFromString<MyModel>(json). The @Serializable data class generated by this converter defines how each key maps to a typed property.

How to read a file in Kotlin?

Use File("data.json").readText() or, on Android, read assets via context.assets. Then decode the text with kotlinx.serialization using the data class this converter generates.

How can I convert JSON to C# classes?

C# uses Newtonsoft.Json or System.Text.Json. OpenToolLab's JSON to Kotlin converter targets Kotlin; the same JSON sample can be converted to TypeScript, Dart, or Swift here, and JSON to C# is a separate ecosystem tool.

Can I convert a JSON file?

Yes — paste the contents of your JSON file into the converter and generate a Kotlin data class. The same sample can also be switched to TypeScript, Dart, or Swift output without re-pasting.

What is {} in JSON?

{} is an empty JSON object. If the converter meets an empty object it generates a minimal data class. Paste a richer sample to get fully typed properties and nested models.

How to get data from JSON in Java?

In Java you typically use Gson or Jackson to deserialize into POJOs. Kotlin developers use kotlinx.serialization data classes, which this converter generates automatically from your JSON sample.

What is the main purpose of JSON?

JSON is the standard text format for exchanging structured data between systems — APIs, configs, and storage. Its purpose here is to describe the shape of your data so a converter can generate matching Kotlin data classes.

How to read a JSON file in Android?

Load the file from assets or resources, read it as a string, then decode with kotlinx.serialization: Json.decodeFromString<MyModel>(text). The @Serializable model this converter generates makes the decode type-safe.

How to work with JSON data in Java?

Use Gson or Jackson to map JSON to POJOs. If you are on Kotlin (the modern Android standard), use kotlinx.serialization with data classes — which is exactly what this JSON to Kotlin converter produces.