# Value (JSON model)

How the SurrealDB Kotlin SDK models values using kotlinx.serialisation JSON types.

The Kotlin SDK models all data - beyond the dedicated [record types](/docs/reference/kotlin/api/values/record-id.md) - using [`kotlinx.serialization`](/docs/reference/kotlin/concepts/serialization.md) JSON types. Read methods return a [`JsonElement`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-element/); write methods accept a [`JsonObject`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-object/).

**Source:** [surrealdb.kotlin](https://github.com/surrealdb/surrealdb.kotlin)

```kotlin title="Import"
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
```

---

## Building values

Construct objects with [`buildJsonObject`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/build-json-object.html).

```kotlin title="Example"
val data = buildJsonObject {
    put("name", "Ada")
    put("age", 36)
}
```

## Decoding values

Rather than navigating raw `JsonElement` trees, decode results into your own [`@Serializable`](/docs/reference/kotlin/concepts/serialization.md) types with [`.queryAs<T>()`](/docs/reference/kotlin/api/core/surreal-client.md#query-as), [`.awaitAs<T>()`](/docs/reference/kotlin/api/core/query-builder.md#await-as), or [`.decode<T>()`](/docs/reference/kotlin/api/core/surreal-client.md#decode).

```kotlin title="Example"
val people: List<Person> = client.queryAs("SELECT * FROM person")
```

> [!NOTE]
> The SDK does not provide dedicated wrapper classes for datetimes, durations, or geometries. Express these as SurrealQL literals or the JSON values SurrealDB expects, and decode results into your own types.

## Learn more

- [Value types](/docs/reference/kotlin/concepts/value-types.md)
- [Serialisation](/docs/reference/kotlin/concepts/serialization.md)
