+
Skip to content

andrewoma/kson

Repository files navigation

Kson Overview

Kson is a library for producing and consuming JSON in Kotlin.

It is a thin wrapper over Jackson. It is heavily inspired by (in fact, it's largely a port from) Play's JSON support.

Status

This is just an experiment - not for production use. However, it does appear to successfully serialise to and from JSON, support building in a DSL fashion and allow extraction of attributes.

An example of manually building JSON:
val person = JsObject(
        "firstName" to "Andrew".js,
        "lastName" to "O'Malley".js,
        "age" to 21.js,
        "adult" to true.js,
        "address" to JsObject(
                "number" to "88".js,
                "street" to "Chapel Street".js,
                "suburb" to "Windsor".js,
                "state" to "VIC".js,
                "postCode" to "3181".js
        ),
        "pets" to JsArray(
                JsObject(
                        "kind" to "dog".js,
                        "name" to "Rover".js
                ),
                JsObject(
                        "kind" to "cat".js,
                        "name" to "Kitty".js
                )
        )
)
An example of extracting data from JSON:
val street = person["address"]["street"].asString() // "Chapel Street"
val petNames = person["pets"].map { it["name"].asString() } // List("Rover", "Kitty")

See the tests for more examples.

Build Status

About

A JSON library for Kotlin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载