jsonObjectColumn

Defines a nullable JSON OBJECT column to store a JSON object.

This function creates and registers a column that specifically stores JSON objects as a JSON OBJECT string. KQLite handles the conversion between the raw JSON string in the database and the KQLiteJsonObject wrapper class. This provides a type-safe way to work with structured JSON data that is known to be an object.

For storing JSON arrays, use jsonArrayColumn. For generic JSON of any type (object, array, string, etc.), use jsonColumn.

Example:

object Products : KQLiteTable("products") {
val id = longColumn("id").primaryKey()

// A nullable JSON OBJECT column to store product properties as a JSON object
val properties = jsonObjectColumn("properties")

// A non-null column with a default empty JSON object
val metadata = jsonObjectColumn("metadata").notNull().default(JsonObjectLiteral("{}"))
}

// Inserting data
Products
.insert()
.bind {
it.properties.bind(JSON_OBJECT("color" to "red", "size" to "M"))
}.execute()

Return

A KQLiteColumn instance representing the JSON object column, which can be further chained with constraints like notNull(), default(), etc.

Author

MOHAMMAD AZIM ANSARI

Parameters

name

The name of the column in the database.

See also