JSON to Kotlin Data Class Converter

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

Key Facts

Category
Developer & Web
Input Types
textarea, text, checkbox
Output Type
text
Sample Coverage
4
API Ready
Yes

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.

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.

Examples

1. Generating Android API Response Models

Android Developer
Background
An Android developer is integrating a third-party weather API that returns a complex nested JSON structure.
Problem
Manually writing Kotlin data classes for a nested JSON response with dozens of fields is time-consuming and error-prone.
How to Use
Paste the weather API JSON response into the input, set the Root Type Name to 'WeatherResponse', check the 'Nullable Properties' option to handle missing fields safely, and generate the code.
Example Config
Root Type Name: WeatherResponse, Nullable Properties: True
Outcome
Instantly generates a set of Kotlin data classes with @SerializedName annotations and nullable types, ready to be used directly with Retrofit.

2. Creating Backend DTOs for User Profiles

Kotlin Backend Engineer
Background
A backend engineer using Ktor needs to parse incoming user registration payloads containing nested address and role arrays.
Problem
Needs to quickly create non-nullable Kotlin data classes that match the incoming JSON structure exactly.
How to Use
Paste the user registration JSON payload, set the Root Type Name to 'UserRegistration', leave 'Nullable Properties' unchecked for strict non-null validation, and copy the output.
Example Config
Root Type Name: UserRegistration, Nullable Properties: False
Outcome
Generates clean, non-nullable Kotlin data classes with nested classes for the address and list types for the roles.

Try with Samples

json

Related Hubs

FAQ

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.

API Documentation

Request Endpoint

POST /en/api/tools/json-to-kotlin

Request Parameters

Parameter Name Type Required Description
jsonInput textarea Yes -
rootName text No -
optionalFields checkbox No -

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-json-to-kotlin": {
      "name": "json-to-kotlin",
      "description": "Convert JSON data into Kotlin data classes with @SerializedName annotations, nullable handling, and nested type inference",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=json-to-kotlin",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]