JSON to Kotlin
Turn a JSON sample into Kotlin data classes with SerialName annotations, nullable fields and List<T>. Everything runs in your browser.
Kotlin · Kotlin 2.0 / kotlinx.serialization. Parsing and type inference happen in this browser tab. Nothing is uploaded and no network request is made.
Is this tool not working?
Tell us what went wrong and we’ll fix it. The report is sent with the page you’re on (/json-to-kotlin/), so you don’t need to name the tool.
About the JSON to Kotlin
JSON to Kotlin generates @Serializable data classes from a JSON sample, ready to use with kotlinx.serialization on Android or the JVM. The parser runs in your browser and walks the sample to infer one Kotlin type per value. Every constructor property gets a @SerialName annotation holding the exact original key, so snake_case or hyphenated JSON names never need a separate mapping layer, while the property itself is idiomatic camelCase. Nested objects become nested data classes instead of generic maps, arrays become List<T>, null values and keys missing from a merged sample become nullable properties with a default of null, and duplicate or reserved names are escaped or given numeric suffixes so the generated file compiles. Numbers deliberately become Double rather than Int, Long or BigDecimal: one occurrence of 42 does not establish the range, precision or integer-only nature of a field, and guessing from a sample is how DTOs quietly lose data. Strings remain String and booleans remain Boolean. A null value, or an array whose elements mix incompatible kinds, falls back to JsonElement from kotlinx.serialization.json; that type can represent any JSON value, so ambiguous input still produces usable code. An empty data class is emitted as a plain @Serializable class, because Kotlin data classes need at least one parameter. A top-level array of objects generates the element data class and a comment recording that the root was an array, so a list of records never leaves you with an anonymous type. Inference is sample-based and limited by design. A field absent from your one sample is assumed to be present; an empty array carries no element type information; and the tool performs no validation of the payloads your app will receive later. It does not infer Instant or LocalDate from strings, sealed class hierarchies from variant records, enums from a few values, or @Required semantics from a single response. Reserved Kotlin keywords are wrapped in backticks while @SerialName keeps their original spelling, and a nested type whose natural name collides with another gets a parent-derived or numbered name. Two different keys that camelCase to the same property name also get suffixes, with their distinct JSON keys preserved in the annotations. Nothing is uploaded: the JSON stays in the tab, and there is no service call, account or rate limit. Use the output to scaffold a DTO layer, then align the types, nullability and defaults with your API documentation, and add your own serializers where formats such as dates or monetary amounts need special handling. Generated code is a fast first draft, not a schema you can trust without review.
How to use it
- Paste a JSON object or an array of objects into the JSON input; Load example inserts a labelled sample response.
- Enter the top-level class name in Root type name. The default is Root, and nested keys provide the other class names.
- Press Generate Kotlin, or use Ctrl/⌘ + Enter in the input box, to run inference locally.
- Copy the generated data classes or download the .kt file, including the kotlinx.serialization imports at the top.
- Review nullability, numeric types and any date or enum fields against the API documentation before committing.
Worked example
Good to know
This tool processes everything locally with JavaScript. Nothing you paste or upload is transmitted to Hellagape or to any third party, and closing the tab clears the data. There is no daily limit and no account requirement. Results are provided for information only; for legal, financial or medical decisions, confirm the outcome with a qualified professional.
FAQ
JSON to Kotlin questions
Which serialization library does the output need?
kotlinx.serialization. The classes use @Serializable and @SerialName, and ambiguous values use JsonElement, so add the core library and the JSON plugin to your Gradle or Maven build. The generated file includes the three imports it needs.
Why Double instead of Int for whole numbers?
Sample-based inference cannot prove that a field is always integral or that it fits in a Kotlin Int. Choosing Int from one value can truncate or overflow later. Double is the neutral choice; change it to Int, Long or BigDecimal once you know the contract.
How are optional and null fields represented?
As nullable types with a default of null, for example val nickname: String? = null. Keys missing from one of several merged array elements are treated the same way. A single object gives no evidence that a key is optional, so that case is assumed required.
What does JsonElement mean in the generated code?
It is kotlinx.serialization’s tree type for arbitrary JSON. It is used for null-only fields and for values whose sample types conflict. It keeps parsing possible, but you will need to inspect it yourself when you want a concrete type.
Are dates and enums inferred?
No. Every JSON string becomes String. Detecting an ISO timestamp or treating three string values as an enum would be a guess based on one payload, so the tool leaves custom serializers, Instant fields and enum definitions to you.
Does this tool send my JSON to a server?
No. Parsing and emission happen entirely in your browser. Nothing is uploaded, stored or logged, and the tool works offline once the page has loaded.
Keep going