JSON to Kotlin Data Class
Convert JSON to Kotlin data classes for kotlinx.serialization, Gson or Moshi, with nested classes and optional nullable fields.
JSON to Kotlin Data Class
import kotlinx.serialization.Serializable
@Serializable
data class User(
var id: Int,
var name: String,
var email: String,
var age: Int,
var active: Boolean,
var score: Double,
var tags: List<String>,
var address: Address,
var metadata: String,
)
@Serializable
data class Address(
var street: String,
var city: String,
)Kotlin data class generated
Updated . Provided as is. Check the output before you rely on it in production.
How to use JSON to Kotlin Data Class
- 1
Paste your JSON data
Paste a JSON object or array. Strings become String, integers Int or Long, decimals Double, booleans Boolean and null Any?.
- 2
Configure data class options
Set the root class name, choose kotlinx.serialization, Gson or Moshi for the matching annotations and imports, and toggle nullable fields.
- 3
Review and copy the code
Nested JSON objects become separate data classes. Copy the output into your Kotlin project.
Questions and answers
What is a Kotlin data class?
What's the difference between the serialization libraries?
What does @Serializable do?
How do nullable fields work?
Can I use the generated code directly?
Use it as an API
JSON to Kotlin Data Class is also callable as a free HTTP JSON API at
https://aidevhub.io/api/json-to-kotlin/ — GET with query
parameters or POST with a JSON body, no authentication, CORS enabled, fair use
(abusive traffic is throttled at the edge; there is no per-request quota header). Responses return
{ ok, tool, result, meta }.
curl -s -X POST https://aidevhub.io/api/json-to-kotlin/ \
-H "Content-Type: application/json" \
-d '{"json":"{\"id\":1,\"name\":\"Alice\"}","root_name":"User"}' Machine-readable contract: /api/tool/json-to-kotlin.json All API endpoints: /agents/ LLM site index: /llms.txt
For AI agents: how to call this tool
Machine-readable contract, endpoints and examples. Humans can ignore this section.
Best Path For Builders
Dedicated API endpoint
Deterministic outputs, machine-safe contracts, and production-ready examples.
Dedicated API
https://aidevhub.io/api/json-to-kotlin/ OpenAPI: https://aidevhub.io/api/openapi.yaml