JSON to Kotlin data class
Paste a JSON sample to get Kotlin data classes: Int, Long and Double types, ? for nullable fields, = null for missing ones, optional kotlinx.serialization.
How to generate Kotlin data classes from JSON
- Paste a JSON sample on the left or open a .json file; the Kotlin code appears on the right.
- Turn on kotlinx.serialization if your project uses it, and rename the root type if you like.
- Copy it or download the .kt file.
Frequently asked questions
The ? says the field may be null. A field that is not always in the JSON also gets = null, so a missing one is not an error.
Each class gets @Serializable, and renamed fields (first_name becomes firstName) get @SerialName("first_name") so the original JSON is still read. Values of unknown type use JsonElement instead of Any.
Whole numbers are Int, very large ones (such as 19-digit IDs) Long, and numbers with decimals Double.
They are Kotlin keywords (such as in, is, object). In backticks they still work as property names.
It is completely free and needs no sign-up.
Related tools
JSON to Java classGenerate Java classes or records from JSONJSON to TypeScriptGenerate TypeScript interfaces from sample JSONJSON Escape / UnescapeTurn text into a valid JSON string and backJSON FormatterFormat, minify and validate JSONJSON RepairAutomatically fix broken JSONJSON CompareFind the differences between two JSON documentsJSON ViewerView JSON as a tree, collapse or expand any branchJSON SorterSort JSON fields and arrays from A to ZJSONPath QueryExtract data from JSON with a JSONPath expression