You are offline. Tools you have opened before keep working.
JSON to Kotlin data class
Paste JSON and get Kotlin data classes with val properties. Optional and null fields become nullable with a default of null, and kotlinx.serialization annotations are added if you want them.
Free and private. Everything runs in your browser, nothing is uploaded.
Report a problem
How it works
Paste your JSONPaste a response from your API or open a .json file. Use Sample to see an example.
Adjust the optionsSet the name of the top level type and the options for this language. The code updates as you type.
Copy or downloadCopy the code into your project or download it as a file.
Data classes for Android and server code
Each JSON object becomes a data class with camelCase properties. With kotlinx.serialization turned on, every class is marked @Serializable and @SerialName keeps the original key wherever the property name differs. Fields of unknown type use JsonElement, which kotlinx.serialization can read without extra code.
Fields that are missing in some items or that can be null are written as nullable types with = null, so decoding does not fail when they are absent. Dates stay String, because kotlinx.serialization has no built in date type; add your own serializer or use kotlinx-datetime if you need date objects. Without the annotations, the classes also work with Moshi, Gson or Jackson.
Frequently asked questions
Why are some properties nullable?
Because the sample shows that they can be missing or null. Making them non null would make decoding fail on such data.
Is my JSON uploaded anywhere?
No. The types are generated in your browser. API responses with customer data or keys never leave your device.
How are optional fields detected?
If the JSON contains a list of objects, every object is compared. A field that is missing from at least one object is marked optional. With a single object, every field is treated as required.
What happens with fields that are always null?
The type cannot be known from the sample, so the field gets a general type such as unknown, object, Any or JsonElement. Add a sample where the field has a value to get a precise type.
Why is my 1.0 typed as a decimal number?
The tool looks at how the number is written. 1.0 or 2.5 become double or float, 1 becomes an integer. If a field is whole in some items and decimal in others, the decimal type is used.
Can I use the result in production code?
Yes, the code compiles as it is in the usual setups. Review names and types before you commit it, because a sample can never show every possible value.
Does it work offline?
Yes. After you open the page once, it keeps working without an internet connection.