talira

A modern JSON library for Android, Java and Kotlin

open sourceApache-2.0free

Moshi is a JSON library for Android, Java and Kotlin from Square that parses JSON into Java and Kotlin classes and writes them back. You build a Moshi instance and ask it for a JsonAdapter for a type; Kotlin classes are handled by code generation with KSP or by a reflection-based adapter factory, and custom adapters handle types it can't convert on its own. It's published as separate artifacts for the core library, Kotlin support, Kotlin code generation and extra adapters.

Problems it solves

  • parse a JSON API response into Kotlin data classes on Android
  • serialize Java objects to JSON with custom adapters
  • a JSON library that understands Kotlin nullability and default values

Features

  • parse JSON into Java and Kotlin classes
  • Kotlin code generation with KSP
  • custom type adapters
  • Android support

Alternatives

The same job

These do what Moshi does.

  1. Gson Google's Java library for converting objects to and from JSON
  2. Jackson The Java JSON library: a suite of data-processing tools for Java and the JVM
  3. FASTJSON 2 High-performance JSON library for Java, the successor to fastjson
  4. JSON-java (org.json) The reference JSON implementation for Java, in the public domain

Compare Moshi with the top 3