Getting started
Create a SimdJsonParser, parse some JSON, and read values out of the result.
The parser holds native resources on some backends, so always close it. The
idiomatic way is Kotlin’s use.
DOM: parse into a tree
parse reads the whole document into an immutable tree of JsonValues:
kotlin
import io.github.devcrocod.simdjson.*
val json = """{ "name": "simdjson-kotlin", "stars": 42, "fast": true }"""
SimdJsonParser().use { parser ->
val root = parser.parse(json) as JsonObject
println((root["name"] as JsonString).value) // simdjson-kotlin
println((root["stars"] as JsonNumber).toLong()) // 42
println((root["fast"] as JsonBoolean).value) // true
}On-Demand: decode only what you touch
iterate returns a lazy, forward-only document. Values are decoded only when
you access them, and nothing builds a full tree:
kotlin
SimdJsonParser().use { parser ->
parser.iterate(json).use { doc ->
val root = doc.getObject()
println(root["name"].getString()) // simdjson-kotlin
println(root["stars"].getLong()) // 42
println(root["fast"].getBoolean()) // true
}
}