The Android Arsenal – JSON

Kotlin extensions for Moshi, Make every thing you want with Moshi in just one line.

Add the JitPack repository to your build file

allprojects {
    repositories {
        maven { url '' }

Add dependency

dependencies {
    implementation 'com.github.mazenrashed:MoshiKotlinExtensions:${LAST_VERSION}'

We have “Student” class to explan the examples

data class Student(var name: String)

Deserialize Json object

private val studentJson = "{"name":"mazen"}"
val student: Student? = studentJson.deserialize<Student>()

Deserialize Json array

private val studentsJson = "[{"name":"Mazen"},{"name":"Mohammad"}]"
val students: List<Student>? = studentsJson.deserializeList()

Serialize Json

private val student: Student = Student("mazen")
val serializedObject = student.serialize()

Check if you can convert json to a particular type

val canConvertStudentJsonToStudent: Boolean = studentJson.canConvertTo( //true

If you have a custom Moshi instance you want to use it (For example: To apply Moshi adapters)

MoshiExtensions.init(YOUR INSTANCE)


We welcome contributions!

  • ⇄ Pull requests and ★ Stars are always welcome.

Enable registration in settings - general
Compare items
  • Total (0)