JSON to Kotlin Converter
Convert JSON to Kotlin data classes for Android and Kotlin development
JSON Input
Kotlin Output
What Is JSON to Kotlin?
Kotlin uses data classes for structured data. When you parse JSON with kotlinx.serialization or Gson, you need matching Kotlin types. This tool generates Kotlin data classes from your JSON structure for use with Json.decodeFromString or Gson.fromJson.
Conversion runs in your browser. Set the data class name and package in the config. Enable Data Class for <code>data class</code> syntax and Nullable Types for optional fields. Nothing is sent to a server.
How to Use This Tool
Paste or Upload JSON
Paste your JSON into the left editor or upload a file. Use <strong>Sample</strong> for example data. Set the root data class name and package in the config. Enable Data Class and Nullable Types as needed.
Review the Generated Types
The right panel shows Kotlin data classes. Nested objects become nested types. Arrays become <code>List<T></code>. Use <code>@SerializedName</code> or <code>@Json</code> if JSON keys differ from property names. For invalid JSON, use the JSON Formatter or JSON Validator first.
Copy or Download
Use <strong>Copy</strong> or <strong>Download</strong>. Paste into your Android or Kotlin project. For formatting JSON first, use the JSON Formatter. For validation, use the JSON Validator.
JSON to Kotlin Examples
Here is an example of generating Kotlin data classes from a JSON object.
Example: Subscriber record
JSON input:
Generated Kotlin output:
When JSON to Kotlin Helps
When building Android apps or Kotlin backend services that consume REST APIs, you need typed data classes. Paste a sample response here to get Kotlin models for Retrofit, Gson, or kotlinx.serialization. For API testing, Postman helps.
Frequently Asked Questions
Data class vs regular class?
Data classes provide equals, hashCode, toString, and copy automatically. They are preferred for DTOs. Enable Data Class in the config for data class syntax.
Nullable types?
Enable Nullable Types for optional JSON fields. Kotlin uses Type? for nullable. Useful when a field can be null or missing in the API response.
Is my data sent anywhere?
No. Generation runs entirely in your browser. No JSON or code is sent to any server.
Gson or kotlinx.serialization?
Both work with the generated data classes. Gson uses @SerializedName for custom key names. kotlinx.serialization uses @SerialName. Add the appropriate annotations if JSON keys differ from property names.
Can I use this with Retrofit?
Yes. Retrofit works with Gson or kotlinx.serialization. Generate the data classes here, then use them as response types in your API interface.
Related Tools
For Kotlin JSON, see kotlinx.serialization and Gson. For JSON, see the JSON specification and RFC 8259. For a general overview, see MDN.