Mock JSON · Gson · Moshi · kotlinx — 3 modes

Convert Kotlin to JSON
Mock data, snippets
or framework guide.

Generate mock JSON from a Kotlin data class, get Gson, Moshi and kotlinx.serialization snippets, or get Retrofit and Ktor JSON patterns. Three modes, one tool.

Your data never leaves your browser
data class → mock JSON
Gson · Moshi · kotlinx snippets
Retrofit · Ktor patterns
Always free
Kotlin to JSON — 3 modes   100% client-side
Kotlin data class input
  Ready

      
Gson vs Moshi vs kotlinx.serialization

The three Kotlin JSON libraries and their one-liner serialization.

LibrarySerializeBest for
Gson Gson().toJson(obj) Legacy Android projects · zero annotations needed · Retrofit GsonConverterFactory
Moshi moshi.adapter(T::class.java).toJson(obj) Modern Android · Kotlin-first · null-safe · Retrofit MoshiConverterFactory
kotlinx Json.encodeToString(obj) KMP · Ktor · official Kotlin library · all targets (Android, iOS, Web, Desktop)
Popular searches
kotlin data class to json kotlin to json kotlin object to json kotlin object to json string kotlin data class to json string kotlin class to json kotlin to json online kotlin data class serialize json kotlinx serialization to json string

Kotlin parsed in your
browser. No IDE needed.

The mock JSON parser reads Kotlin data class property declarations — val/var with type annotations. It handles nullable types (Type?), List<T> generics and nested class references. The snippets cover the three main Kotlin JSON libraries with complete Gradle dependency coordinates and all common serialization scenarios.

3 libraries covered
Gson, Moshi and kotlinx.serialization — complete Gradle dependencies, imports and real-world usage patterns for each.
Retrofit + Ktor patterns
Complete Retrofit service interface with @Body annotation and Ktor client with ContentNegotiation plugin — the two main HTTP clients for Kotlin.
KMP-ready
The kotlinx.serialization and Ktor patterns work on all Kotlin Multiplatform targets — Android, iOS, Desktop and Web.
47 tools, always free
No file size limits, no watermarks, no account. Funded by non-intrusive display advertising only.
Frequently asked questions
How do I convert a Kotlin data class to JSON?
With Gson: val json = Gson().toJson(myObject). With kotlinx.serialization: annotate with @Serializable then call Json.encodeToString(myObject). With Moshi: build a Moshi instance and get a JsonAdapter. Select the Snippets mode for complete code with Gradle dependencies.
Which Kotlin JSON library should I use?
For new Android projects: Moshi with codegen adapters — Kotlin-first, null-safe, no reflection. For Kotlin Multiplatform: kotlinx.serialization — the only option that works on all targets. For legacy Android: Gson — zero configuration, works without annotations. All three integrate with Retrofit.
Is the Kotlin to JSON converter free?
Yes, completely free. No file size limits, no account required. JSONshift is funded by non-intrusive display advertising.
Go up