Overview
Turn a JSON sample into a Kotlin data class with property types inferred from the values you paste. Everything is computed locally in your browser, so proprietary API payloads stay on your machine. The output is a ready-to-paste data class declaration with val properties.
How It Works
A sample object is preloaded so you can see the shape of the output straight away. Edit the JSON in the input editor and the data class regenerates live. Invalid JSON or a scalar shows a red error with no code; a top-level array of objects is accepted and described by one data class. Click the output panel to copy the entire declaration in one action.
Step-by-Step Usage Guide
- Paste your JSON object into the input editor on the left.
- Check the generated data class in the output panel.
- Replace List<Any> for empty arrays and Any? for null-only fields with concrete types, and move the generated nested data classes where you want them.
- Click the output to copy, then add your serialization annotations in the IDE.
Technical Specifications & Standards
The type mapper is shared with the other JSON-to-language converters on this site but emits Kotlin types: strings map to String, booleans to Boolean, whole numbers to Long, decimals to Double, and a field that is always null to Any? = null (a null mixed with real values gives a nullable type with a null default). Arrays become List<T> with the element types of all items merged, an empty array becomes List<Any>, and each nested object becomes its own data class named after its key. Property names are kept when they are valid Kotlin identifiers, so snake_case keys stay as they are, which compiles fine but differs from Kotlin convention; invalid keys such as first-name are camelCased with a // JSON key comment, and Kotlin keywords are wrapped in backticks. Because the output is a data class, you get equals, hashCode, toString, and copy for free once the types compile. For real deserialization work pair the generated class with kotlinx.serialization or Moshi and add the annotations those libraries need, such as @SerialName for keys that are not valid Kotlin identifiers.
Targeted Use Cases
- Generating a response model for a Kotlin or Android app consuming a JSON API.
- Drafting configuration data classes from JSON configuration files.
- Reviewing how a payload's types translate into Kotlin during code review.
- Creating test fixtures with a realistic data class shape.
Notes & Gotchas
- Include at least one element in every array so the item type is inferred.
- Decide explicitly which properties should be nullable; null samples produce Any?, which is rarely the long-term type you want.
- Rename properties to camelCase and add @SerialName or @JsonProperty for wire-format keys.
- Keep the properties immutable (val) as generated unless you have a specific reason not to.
Frequently Asked Questions
What does an empty array produce?
With no elements there is nothing to infer from, so the generator emits List<Any> instead of guessing. Replace it with List<String>, List<Item>, or your own type based on the API documentation.
Why Any? for null values?
Kotlin's type system needs a concrete type for each property. When the sample value is null the generator cannot know the intended type, so it falls back to the nullable supertype Any?. Narrow it to String?, Long?, or another concrete nullable type.
Are my API keys sent to a server?
No. Parsing and code generation happen in the page with plain JavaScript. The tool works offline once loaded, and nothing you paste is transmitted or stored.
Does it handle nested objects?
Yes. Each nested object becomes its own data class, declared beside the parent rather than inside it, and the parent property uses that type. Rename or nest the classes as you prefer.