• Start

Languages

/

Kotlin

/

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 types with .queryAs<T>(), .awaitAs<T>(), or .decode<T>().

Example

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

Was this page helpful?