Kotlin to JSON Converter
Paste Kotlin data classes or objects. Get clean JSON back.
Input
Output
Paste your Kotlin code on the left and press Convert.
Or drop a file on this box, , or .
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.
Annotations are taken into account: @SerialName("order_id") renames a key and @Transient leaves a property out. A property you did not set in the constructor call shows its default value. Put several data classes in one paste and every class gets an entry at the top of the output, nested types are written out, and sealed hierarchies are reduced to their concrete subclasses. For Android work, the result is ready for a Retrofit mock response or a Room test seed.
How to use it
A single instance or a whole Models.kt: either way there are three steps.
Paste your Kotlin (or load the sample)
Paste Kotlin into the left editor without cleaning it up: data classes, regular classes, object declarations, sealed hierarchies, the imports above them. Load Sample loads @Serializable data classes, an Instant timestamp and a nullable notes property that defaults to null.
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
Hit the green Convert button. The file is posted to the backend, which matches the named arguments to the properties and replies with JSON; a "Converting..." overlay sits over the editors until then.
Copy the JSON
Indented JSON lands on the right, where the panel is read-only. Copy it from there into a MockWebServer response, a Room fixture, the examples in your OpenAPI file or an HTTP client. Change the Kotlin and convert again whenever the model moves.
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 @Serializable annotation.
Docs that stay in sync
Fill the example blocks of your OpenAPI spec from the data classes your Ktor or Spring service actually returns, and regenerate them when a field is added.
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. Nothing is compiled; the backend reads your source and writes JSON, so no Gradle plugin is involved. Inside your app, kotlinx.serialization is the Kotlin-native option and jackson-module-kotlin suits projects already built on Jackson.
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 are written as ISO 8601 text, for example "2026-04-20T10:30:00Z". A UUID keeps its dashed form inside quotes, and a Duration becomes an ISO 8601 duration such as "PT15M".
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 Kotlin is posted to the backend just for this conversion and is not stored. BuildConfig constants and default arguments are where API keys tend to hide, so check those first.
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 often ships next to Swift on iOS or Java on the server. These cover those sides of the codebase, plus the JSON checks afterwards: