simdjson-kotlin v0.1.0

Examples

Parsing twitter.json

A classic simdjson benchmark input is twitter.json, a Twitter API response with a top-level statuses array. The task below is the same in every tab: print the screen name of every user whose default_profile is true.

Each API expresses it differently. Compare the three and pick the one that fits your access pattern.

val json: ByteArray = loadTwitterJson()

SimdJsonParser().use { parser ->
    val root = parser.parse(json) as JsonObject
    val statuses = root["statuses"] as JsonArray
    for (tweet in statuses) {
        val user = (tweet as JsonObject)["user"] as JsonObject
        if ((user["default_profile"] as JsonBoolean).value) {
            println((user["screen_name"] as JsonString).value)
        }
    }
}

New to these APIs? Start with the DOM, On-Demand, and serialization guides.