# Quickstart

Parse your first JSON document with the DOM and On-Demand APIs.


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`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/use.html).

## DOM: parse into a tree

`parse` reads the whole document into an immutable tree of `JsonValue`s:

```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
    }
}
```

<aside class="kt-callout kt-callout--note">
  <svg class="kt-callout__icon" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 5h18"/><path d="M3 12h18"/><path d="M3 19h12"/></svg>
  <div class="kt-callout__body"><strong class="kt-callout__title">Which API should I use?</strong><div class="kt-callout__content">Reach for the <a href="/simdjson-kotlin/guides/dom/index.md">DOM API</a> when you need random access or want
to keep the parsed values around. Reach for the
<a href="/simdjson-kotlin/guides/on-demand/index.md">On-Demand API</a> when you read each field once, in
order: it&rsquo;s faster and allocates far less. On the JVM you can also decode
straight into <code>@Serializable</code> classes with the
<a href="/simdjson-kotlin/guides/serialization/index.md">serialization module</a>.</div>
  </div>
</aside>

