JSON to KotlinONLINE

Generate Kotlin types or models from sample JSON and download .kt code.

1 MiB per input · Ctrl / ⌘ + Enter to run

quicktype infers shapes from a sample up to 128 Ki characters. Review field optionality, names, and type choices before adding generated code to your project.

Result
Ready. Paste input, then run the tool.
Your JSON stays in your browser. Core processing happens locally.
THE PRACTICAL GUIDE

Draft Kotlin data classes from a JSON API sample

JSON to Kotlin creates a draft Kotlin model from a sample JSON response. It helps mobile or JVM developers begin mapping a nested API shape.

When should you use it?

  • Sketch data classes for a Kotlin client.
  • Inspect nested arrays in a response model.
  • Compare sample data with an existing serializer contract.
WORKED EXAMPLE

Example: infer Kotlin fields from JSON

This abbreviated example shows the inferred name and active fields in Kotlin. The full generated file includes imports and helpers and may change with generator versions; review it before adding it to a project.

Sample JSON
{"name":"Alex","active":true}
Illustrative model excerpt
data class Root(
    val name: String,
    val active: Boolean
)

Match the model to your JSON library

A Kotlin data class describes fields, while the serializer determines how wire names, constructors, defaults, and unknown keys are handled. Review the imports, annotations, and helper code in the full generated output. Adapt the model deliberately if your application uses a different serialization library or naming strategy.

Use nullability to express the contract

A nullable field, a constructor default, and an omitted JSON member are related but different cases. Decide which ones the API permits before treating the inferred type as final. A sample containing only a successful response cannot show every error or variant. Test at least the absent-field and null cases for values that are optional in the contract.

IN PRACTICE

How do I generate Kotlin data classes from nested JSON?

Generate Kotlin source from a realistic nested sample. The result models observed objects and arrays as Kotlin types and may include Jackson serialization support. Use it as a draft for your chosen Android or JVM serialization stack.

Illustrative Kotlin data class

kotlin
data class Root (
    val name: String,
    val active: Boolean
)

The full .kt file includes annotations and helper code. Check library compatibility, property naming, and nullability.

An empty sample contains no item values to infer. Add representative items or edit the type manually to match the API contract.

BEFORE YOU USE THE RESULT

What should you check before using the result?

Confirm nullability, property names, serialization annotations, and library compatibility in your project. Generated declarations do not validate future responses.

Understand JSON syntax

Technical reference: quicktype model generation documentation

THE JSON FIELD GUIDE
All guides