jp.nephy:jsonkt

Json bindings for Kotlin.


Keywords
json, json-model, json-parser, kotlin, kotlin-multiplatform
License
MIT

Documentation

Json.kt: Json bindings for Kotlin Multiplatform

Kotlin GitHub release (latest by date) GitHub Workflow Status license issues pull requests

槔è­Čăƒ—ăƒ­ăƒ‘ăƒ†ă‚Łă‚’äœżă„, ç›Žæ„Ÿçš„ă« JSON を Kotlin ăźă‚Żăƒ©ă‚čă«ć€‰æ›ă§ăăŸă™ă€‚
Using delegated properties, you can intuitively convert JSON to Kotlin classes.

珟時ç‚čでは JVM (Android), JS target ă«ćŻŸćżœă—ăŠă„ăŸă™ă€‚
At present, it supports Java 8 or later, Android, and JavaScript target.

ăƒ‰ă‚­ăƒ„ăƒĄăƒłăƒˆăŻ こちら ă§ć…Źé–‹ă—ăŠă„ăŸă™ă€‚
Documentation is available at here.

data class Model(override val json: JsonObject): JsonModel {
    val a by int
    val b by float
    val c by string
    val d by intList
    val e by model { E(it) }
    val f by modelList { E(it) }

    data class E(override val json: JsonObject): JsonModel {
        val x by nullableString
        val y by double
        val z by int
    }
}

private val json = """{
    "a": 1,
    "b": 2.3,
    "c": "hoge",
    "d": [2, 3, 5, 7],
    "e": {
        "x": "1",
        "y": 2.0,
        "z": 3
    },
    "f": [
        {
            "x": "1",
            "y": 2.0001,
            "z": 3
        },
        {
            "x": null,
            "y": 20.00001,
            "z": 30
        }
    ]
}"""

fun main() {
    val model = json.parseObject { Model(it) }

    assertEquals(1, model.a)
}

Get Started

Json.kt ăŻăƒăƒŒă‚žăƒ§ăƒł 6.0.2 から Maven Central ă§ć…Źé–‹ă•ă‚ŒăŠă„ăŸă™ă€‚ä»„ć‰ăź Bintray ăƒȘポゾトăƒȘăŻă‚‚ă†ćˆ©ç”šă§ăăŸă›ă‚“ă€‚
Json.kt is now available in the Maven Central since version 6.0.2. The previous Bintray repository is no longer available.

GitHub release (latest by date)

dependencies {
    implementation("blue.starry:jsonkt:$JsonKtVersion")
}

License

Json.kt is provided under the MIT License.

Copyright (c) 2017-2021 StarryBlueSky.