# JSON to Kotlin Data Class Converter

Convert JSON data into Kotlin data classes with @SerializedName annotations, nullable handling, and nested type inference

> Canonical page: https://elysiatools.com/en/tools/json-to-kotlin

- **Category:** Development

- **Keywords:** json, kotlin, data class, convert, transform, codegen, json to kotlin, SerializedName, gson, moshi, dto

## Overview

The JSON to Kotlin Data Class Converter simplifies Android and backend development by instantly generating clean, type-safe Kotlin data classes from raw JSON payloads. It automatically infers nested object structures, handles arrays, generates @SerializedName annotations for serialization libraries, and supports nullable property configurations.

## Inputs

- **JSON Input** (textarea): { "name": "Alice", "age": 30, "roles": \["admin", "user"\], "address": { "city": "Shanghai", "zip": "200000" } }
- **Root Type Name** (text): Root
- **Nullable Properties** (checkbox)

## When to use

- When integrating a new REST API and you need to quickly generate Kotlin Data Transfer Objects (DTOs) from JSON response payloads.
- When migrating legacy Java models or manual JSON parsing code to clean, idiomatic Kotlin data classes.
- When configuring serialization models that require custom field mapping annotations alongside nullable property definitions.

## How it works

- Paste your raw JSON payload into the JSON Input text area.
- Specify the Root Type Name and toggle the Nullable Properties option if your API fields can be null.
- Copy the generated Kotlin code, complete with nested classes and @SerializedName annotations, directly into your project.

## Use cases

- Generating Retrofit API response models for Android application development.
- Creating Kotlin DTOs for Spring Boot or Ktor backend services consuming external JSON APIs.
- Rapidly prototyping data structures during initial API design phases.

## Frequently asked questions

### Does this tool support nested JSON objects?

Yes, it automatically detects nested objects and generates corresponding nested Kotlin data classes.

### How does the tool handle JSON arrays?

It infers the item type within the array and represents it as a Kotlin List of that type.

### Can I make all generated properties nullable?

Yes, checking the Nullable Properties option will append a question mark to all property types, making them nullable.

### What annotations are added to the generated Kotlin classes?

The tool generates @SerializedName annotations for each property to ensure compatibility with serialization libraries like Gson.

### Do I need to define names for nested classes manually?

No, the converter automatically infers appropriate class names for nested objects based on their JSON key names.

## Related tools

- [Data URI Generator](https://elysiatools.com/en/tools/data-uri-generator): Convert files into Data URIs (Base64 or percent-encoded) for inlining images, fonts, and assets directly into HTML, CSS, or Markdown
- [JSON Schema to Zod Schema Converter](https://elysiatools.com/en/tools/json-schema-to-zod-schema-converter): Convert JSON Schema JSON/YAML definitions into ready-to-use Zod schemas with nested objects, arrays, enums, and common validation rules
- [JSON to C# Class Converter](https://elysiatools.com/en/tools/json-to-csharp): Convert JSON data into C# classes with PascalCase properties, JsonPropertyName attributes, and nested type inference
- [JSON to Go Struct Converter](https://elysiatools.com/en/tools/json-to-go): Convert JSON data into Go struct definitions with json struct tags, exported PascalCase fields, and nested type inference
- [JSON to Java Class Converter](https://elysiatools.com/en/tools/json-to-java): Convert JSON data into Java classes with Jackson @JsonProperty annotations, private fields, getters, and setters
- [JSON to Rust Struct Converter](https://elysiatools.com/en/tools/json-to-rust): Convert JSON data into Rust structs with serde Serialize/Deserialize derives, snake_case fields, and serde rename attributes
- [JSON to TypeScript Converter](https://elysiatools.com/en/tools/json-to-typescript): Convert JSON data into TypeScript interfaces or type aliases with union types, optional fields, and nested object inference
- [Log Sequence Diagram Converter](https://elysiatools.com/en/tools/log-sequence-diagram-converter): Convert structured service logs into Mermaid or PlantUML sequence diagrams, with optional latency and error annotations

## Samples

- [Android Serialization Kotlin Samples](https://elysiatools.com/en/samples/android-serialization-kotlin): Android Kotlin serialization examples including JSON serialization, deserialization, and XML parsing
- [Terraform Plan JSON Samples](https://elysiatools.com/en/samples/terraform-plan-json-samples): Sample Terraform plan JSON files exported from terraform show -json style payloads for dependency visualization and change review
- [Chat Transcript JSON Samples](https://elysiatools.com/en/samples/chat-transcript-json): JSON examples for multi-role chat transcripts
- [JSON Samples](https://elysiatools.com/en/samples/json): JSON (JavaScript Object Notation) format examples from simple to complex structures

## Related content

- [JSON to Typed Code Generators (TypeScript, Go, Rust, Kotlin, Java, C#)](https://elysiatools.com/en/hubs/json-to-typed-code-generators): Paste JSON and get ready-to-use types: TypeScript interfaces, Go structs, Rust structs with serde, Kotlin data classes, Java classes, C# classes, Zod schemas, and inferred JSON Schemas.
- [JSON Interchange and Format Translation Tools](https://elysiatools.com/en/hubs/json-convert): Compare JSON conversion tools for CSV, YAML, TOML, GraphQL, XML, Markdown, Excel, BSON, EDN, and related structured formats in one hub.
- [JSON Inspection, Diff, and Transformation Tools](https://elysiatools.com/en/hubs/json-utility): Compare JSON formatting, diffing, path inspection, schema validation, merging, transformation, and export tools in one hub for API and data workflows.
- [JSON Schema, Mock Data, and API Fixture Generators](https://elysiatools.com/en/hubs/json-generate): Curated tools for JSON schema generation, mock payload building, and API fixture preparation in one hub.
