• Start

API Reference

/

Data types

Value (JSON model)

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

The Kotlin SDK models all data — beyond the dedicated record types — using kotlinx.serialization JSON types. Read methods return a JsonElement; write methods accept a JsonObject.

Source: surrealdb.kotlin

Import
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put

Construct objects with buildJsonObject.

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

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

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.

Was this page helpful?