What is JSON to Kotlin Data Class Generator?
This tool converts JSON data into Kotlin data classes with optional kotlinx.serialization annotations. It automatically infers types, converts camelCase to snake_case, detects ISO dates, and generates ready-to-use Kotlin code.
How to Use
- Set the root class name and configure options (kotlinx.serialization, snake_case, date detection, nullable types)
- Paste your JSON data into the input area
- Click "Generate Kotlin Code" and copy the output into your project
Why Use This Tool?
Tips & Best Practices
- Use realistic sample data — type inference depends on actual values
- Enable snake_case conversion for idiomatic Kotlin field names
- kotlinx.serialization annotations ensure JSON keys match original camelCase names
- Nullable types (T?) are inferred from null values in your JSON
Frequently Asked Questions
What is kotlinx.serialization?
kotlinx.serialization is Kotlin's official serialization library. It provides @Serializable and @SerialName annotations that enable type-safe JSON parsing. When enabled, the generated classes can be used with Json.decodeFromString<T>() and Json.encodeToString() for seamless JSON conversion.
How are JSON types mapped to Kotlin?
JSON strings → String, integers → Int, floats → Double, booleans → Boolean, null → T? (nullable), arrays → List<T>, objects → separate nested data classes. ISO-8601 date strings can be detected as Instant or LocalDate when the option is enabled.
How are nested objects handled?
Nested JSON objects are converted to separate Kotlin data classes. They are ordered children-first, so nested classes appear before the parent class that references them, ensuring valid Kotlin code.
Is my data sent to a server?
No, all processing happens entirely in your browser. Your JSON data never leaves your device.