CoreJSON

JSON to Kotlin

This JSON to Kotlin tool generates concise data classes with support for Jackson, kotlinx.serialization and Klaxon plus a custom package name, with nullable (?) types inferred accurately. Generation runs locally in your browser, suited to both Android and server-side development.

Open in the workbench Runs locally · nothing is uploaded

How to use it

  1. 1

    Paste your JSON

    Paste API JSON; nested objects produce related data classes and collections become List<T>.

  2. 2

    Choose framework and package

    Pick Jackson (Spring ecosystem), kotlinx.serialization (official / KMP) or Klaxon, and enter a package name.

  3. 3

    Copy the Kotlin code

    Data classes with accurate nullable annotations are generated; copy them into your project.

  4. 4

    Wire into your project

    Add the matching serialisation plugin or dependency, then deserialise the response.

Key features

Three serialisation options

Jackson annotations, kotlinx.serialization with @Serializable, or the lightweight Klaxon — switch as needed.

Accurate null-safety

Null fields and multi-sample analysis determine which fields get a ?, reducing NPEs and non-null assertions.

Concise data class output

Primary-constructor properties with defaults; equals/hashCode/toString/copy come for free from Kotlin.

Configurable package

The package declaration follows your project convention so multi-module Android projects can drop it straight in.

Default values for nullable fields

Nullable fields default to null so deserialisation does not throw when a key is missing.

Local and private

Generation runs in your browser and the data is not uploaded.

Common errors & troubleshooting

  • ! Android with Retrofit commonly uses kotlinx.serialization or Moshi; if you choose Jackson annotations here you can tweak them by hand.
  • ! A Spring Boot Kotlin backend can use Jackson directly by adding jackson-module-kotlin.
  • ! A pure data class (types only) carries no framework annotations and can also be deserialised with Gson.
  • ! Review the required semantics against the API docs, since defaults are inferred from sample presence.

Frequently asked questions

Why do some field types have a question mark?

When a field is null or missing in the JSON it is treated as nullable (String?). Kotlin null-safety requires an explicit marker, so the compiler forces a null check when the value is used.

How do I set up kotlinx.serialization?

After choosing the kotlinx framework, classes carry @Serializable and fields carry @SerialName. The project must enable the kotlin("plugin.serialization") plugin and add the kotlinx-serialization-json dependency.

How are field default values decided?

Nullable fields default to null so that deserialisation does not throw on a missing key; non-null fields are inferred from sample presence, and you should verify the required semantics against your API docs.

Is my data uploaded?

No. Generation runs locally in your browser.

Related tools