Convert Kotlin classes to JSON!

Paste Kotlin data class code and get an example JSON! Supports kotlinx.serialization @SerialName, Jackson, Gson and Moshi. Handy for API docs and mock request bodies.
Kotlin
Result
 

Convert Kotlin classes to JSON!

Paste an existing Kotlin data class and see what it looks like once serialized, as a sample JSON document. Nested classes, List/Map properties and enums are followed and filled in, and renaming annotations such as @SerialName are applied to the keys.

Reach for it when a server and an app share models and you need to confirm which JSON a class really sends and receives, or when an API doc or mock server needs a request body sample.

How to use

  1. Paste your Kotlin source. import/package lines and member functions can stay in; they are skipped.
  2. Leave Root type on Auto in most cases: the first class not referenced by another class becomes the root. You can also pick a specific class from the list.
  3. Copy the JSON into a Swagger example, a Postman request body or a test fixture.
  4. Types defined elsewhere (say, a Money class from another file) come out as null, and their names are listed next to the options. Paste those classes too and they get filled in.

Example

Input (Kotlin)
@Serializable
data class Article(
    val id: Long,
    val title: String,
    @SerialName("author_name") val authorName: String,
    val status: PostStatus = PostStatus.DRAFT,
    val tags: List<String> = emptyList(),
    val publishedAt: Instant? = null,
    @Transient val cachedHtml: String = "",
)

@Serializable
enum class PostStatus {
    @SerialName("draft") DRAFT,
    @SerialName("published") PUBLISHED,
}
Output (JSON)
{
  "id": 0,
  "title": "",
  "author_name": "",
  "status": "draft",
  "tags": [
    ""
  ],
  "publishedAt": "1970-01-01T00:00:00Z"
}

authorName is emitted as author_name because of @SerialName, and the default PostStatus.DRAFT resolves to "draft" through the enum entry's own @SerialName. cachedHtml is marked @Transient, so it is dropped. A nullable property defaulting to null, like publishedAt, still gets a typed sample (Instant → ISO timestamp) rather than null.

Supported features

  • Key renaming: kotlinx.serialization @SerialName, Jackson @JsonProperty, Gson @SerializedName and Moshi @Json(name = ...).
  • Excluded: properties marked @Transient or @JsonIgnore, private properties, delegated ones like by lazy, getter-only computed properties, const values and companion object members.
  • String, number and boolean literal defaults are used as the sample value; a default such as Status.PAID becomes that entry's JSON value.
  • Enums use their first entry, honoring an entry-level @SerialName.
  • Dates and times: LocalDate → 1970-01-01, LocalDateTime → 1970-01-01T00:00:00, Instant/OffsetDateTime → ISO string ending in Z, Duration → PT0S; UUID gets a well-formed value.
  • List, Set and Array get one sample element; a map with a numeric key type such as Map<Int, V> uses "0" as the key.
  • Self-referencing classes (trees, threaded comments) are cut off with null or an empty array instead of expanding forever.

Use cases

API documentation for Ktor or Spring services

Paste a response DTO and you have the JSON skeleton for an OpenAPI example or a README. Fields renamed through @SerialName appear under the same name the serializer will actually write.

Fake responses for Android tests

Build the body for MockWebServer or a local JSON fixture from the very model your Retrofit interface returns. Swap the placeholder values ("", 0) for realistic data and the structure still matches the model.

Agreeing on key names with the backend

Show the server team exactly what the app sends, or compare a received spec against your Kotlin model to catch key-name mismatches before they become runtime errors.

Notes and limitations

  • Values are type placeholders ("", 0, false), not realistic data; replace them before publishing docs.
  • Nullable properties (String?) also get a typed sample rather than null, so mark separately which fields may actually be null.
  • Global naming rules such as Jackson @JsonNaming or kotlinx JsonNamingStrategy are not applied; unannotated properties keep their Kotlin name as the key.
  • Polymorphic sealed hierarchies (a type discriminator) and custom KSerializers are not reflected.
  • Defaults built from function calls, like emptyList() or listOf(...), are not evaluated; the value comes from the declared type instead.

FAQ

A @Transient property is missing from the output. Is that expected?

Yes. kotlinx.serialization @Transient and Jackson @JsonIgnore keep a field out of serialization, so the sample omits it too. A private val declared in the class body is left out for the same reason.

Does it read models written for Gson or Moshi?

The class syntax is the same, so they parse fine. Renames from Gson @SerializedName("...") and Moshi @Json(name = "...") are recognized.

I declared = null, so why does the field have a value?

The goal is to show each field's shape, so a null default is ignored and a typed sample is used. That way you can see, for example, which string format an Instant? travels as.

My classes live in several files. What should I paste?

Paste them one after another into the same input. Any type still missing is named next to the options, which tells you what else to add.