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.
How to use it
- 1
Paste your JSON
Paste API JSON; nested objects produce related data classes and collections become List<T>.
- 2
Choose framework and package
Pick Jackson (Spring ecosystem), kotlinx.serialization (official / KMP) or Klaxon, and enter a package name.
- 3
Copy the Kotlin code
Data classes with accurate nullable annotations are generated; copy them into your project.
- 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
JSON to Java
Generate Java POJOs from JSON with fields, getters/setters and type inference. Choose Jackson, Lombok + Jackson or a plain POJO, and set a custom package name. Runs locally in a Web Worker.
JSON to Swift
Generate Swift models from JSON that conform to Codable. CodingKeys handle snake_case mapping, and optional properties are inferred. Choose struct or class. Runs locally in your browser.
JSON to Dart
Generate Dart model classes for Flutter projects from JSON, including fields, a constructor and fromJson / toJson methods, with accurate nullable types and json_serializable or Freezed styles.
JSON Formatter
Format, beautify and validate JSON in your browser. Errors point to the exact line and column, and you can indent with 2 spaces, 4 spaces or a tab.