Kotlin to JSON Converter
Paste Kotlin data classes or objects. Get clean JSON back.
What this tool does
If you have ever had to hand-write a JSON payload that mirrors a Kotlin data class — for a unit test, a fixture, or an API call — you know how much yak-shaving is involved. Normally you reach for kotlinx.serialization, annotate the class, and run the app to capture the output. Paste the Kotlin here and get valid JSON back without any of that — no Gradle plugin, no @Serializable, no runtime.
The converter respects how Kotlin values actually serialize. val price: Double = 49.99 becomes a JSON number, val tags: List<String> becomes a JSON array, and val address: Address? with null becomes JSON null. Instant, LocalDate, and LocalDateTime from kotlin.stdlib come out as ISO-8601 strings. UUID becomes a standard hex string. Map<String, V> becomes a JSON object, and enum class values come out as their string name — the same behaviour you would get from Gson or jackson-module-kotlin.
Serialization annotations are honoured. @SerialName("x") renames the JSON key, @Transient drops the property. Default parameter values are emitted when the property is not explicitly set. Paste several data classes at once and each one comes out as a top-level entry, with nested types expanded and sealed class hierarchies flattened into their variants. If you are shipping an Android app, the output drops straight into Retrofit fixtures and Room test seeds.
How to use it
Three steps. Works the same whether you paste a one-off instance or a whole file full of data classes.
Paste your Kotlin (or load the sample)
Drop your Kotlin into the left editor as-is. A data class, a regular class, an object declaration, multiple classes, or sealed hierarchies — all fine. Click Load Sample to see a realistic example first.
You do not need to strip imports, packages, or annotations. Leave the Kotlin syntax as-is — companion objects and backing fields are fine too.
Hit Convert
Click the green Convert button. The tool reads the Kotlin, preserves every data class and property, and emits the JSON in one pass. A short loading indicator runs while it works.
Copy the JSON
The right panel fills with indented JSON. Copy it into your Retrofit test, a Room fixture, your OpenAPI examples, or a REST client. That is the whole loop.
When this actually comes in handy
Android app API fixtures
You have a Retrofit request model and need a JSON payload to drop into MockWebServer or Postman. Paste the data class, grab the JSON, move on.
Backend test data
A Ktor or Spring service with 30 data classes. Convert each one to JSON seed files for integration tests without writing a single <code>@Serializable</code> annotation.
Docs that stay in sync
Generate JSON examples for your OpenAPI spec or API reference straight from the real data classes, so the docs never drift from the models.
Config file starters
A Settings data class with two dozen properties becomes a ready-to-edit JSON template — no handwritten boilerplate.
Common questions
Do I need kotlinx.serialization or Jackson installed?
No. This tool runs server-side and does not compile your code — you get JSON without any plugin. If you want runtime serialization in your app, kotlinx.serialization is the native choice; jackson-module-kotlin works too.
Does it honour @SerialName, @Transient, and @JsonProperty?
Yes. @SerialName("x") and @JsonProperty("x") rename the JSON key, and @Transient / @JsonIgnore remove the property from the output — matching kotlinx.serialization semantics.
What about Instant, LocalDate, and UUID?
Instant, LocalDate, LocalDateTime, and ZonedDateTime all come out as ISO-8601 strings. UUID becomes a standard 8-4-4-4-12 hex string. Duration becomes a duration string.
How are nullables, sealed classes, and enums handled?
Nullable properties with a null value become JSON null; otherwise the inner type serializes normally. Sealed class instances include a type discriminator by default (configurable if you use kotlinx.serialization). Enums come out as their string name unless annotated otherwise.
Is my code stored?
Your code is sent to the backend for conversion and is not persisted — we do not log the payload. As always, give sensitive code a quick review before pasting.
Does it work for both Kotlin/JVM and Kotlin Multiplatform code?
Yes. As long as the syntax is valid Kotlin, the converter does not care whether the target is JVM, JS, Native, or Multiplatform. Platform-specific types that do not have a JSON representation (such as Job or Flow) come out as null.
Other tools you may need
Kotlin to JSON is one piece of the puzzle. These pair well with it: