Parse JSON responses from a REST API into Kotlin data classes in an Android app with minimal boilerplate.
Write a custom adapter to handle a JSON format where dates arrive as Unix timestamps but your class uses a Date object.
Use Moshi's code generation to skip runtime reflection and get faster, null-safe JSON parsing in a Kotlin app.
Serialize your app's data objects back to JSON to send as a request body to a web server.
Moshi is a library for Android, Java, and Kotlin developers that handles reading and writing JSON data. JSON is a common text format that apps use to send and receive data, for example from a web server. Moshi converts between JSON text and the Java or Kotlin objects your code actually works with, so you do not have to manually pick apart the text yourself. The basic usage is straightforward: you point Moshi at a class you have defined, and it reads JSON into instances of that class or writes instances of that class back into JSON. It handles common data types automatically, including numbers, strings, lists, maps, and custom classes with multiple fields. Where Moshi stands out is in its support for custom adapters. If the JSON format you receive does not match your class structure directly, you write a small adapter class with methods marked @FromJson and @ToJson. Moshi calls those methods during conversion, letting you transform the data, rename fields, combine multiple fields into one, or change the format entirely. This keeps your main data classes clean while the conversion logic stays in a separate, reusable place. For Kotlin specifically, Moshi offers a code generation option that creates the adapter code at compile time rather than using reflection at runtime. This is faster and avoids some edge cases with Kotlin's null safety system. Kotlin data classes are well supported. Java reflection is also available for Java codebases. Moshi is developed and maintained by Square, the payments company, and is distributed as a dependency you add to your build file. The README provides working examples in both Java and Kotlin for all major features.
← square on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.