json Column
Defines a nullable JSON column to store any valid JSON data.
This function creates and registers a column that stores JSON data (objects, arrays, strings, numbers, booleans, or null) as a JSON string. KQLite handles the conversion between the raw JSON string in the database and the KQLiteJson wrapper class. This provides a type-safe way to work with generic JSON content when the exact structure (object or array) is not known or can vary.
For more specific JSON structures, consider using jsonObjectColumn for JSON objects or jsonArrayColumn for JSON arrays.
Example:
object Logs : KQLiteTable("logs") {
// A nullable JSON column to store arbitrary JSON payload
val payload = jsonColumn("payload")
}
// Storing a JSON object
Logs
.insert()
.bind {
it.payload.bind(JSON("""{"status":"ok", "code":200}"""))
}.execute()
// Storing a JSON array
Logs
.insert()
.bind {
it.payload.bind(JSON("""[1, "test", true]"""))
}.execute()Return
A KQLiteColumn instance representing the JSON column, which can be further chained with constraints like notNull(), default(), etc.
Author
MOHAMMAD AZIM ANSARI
Parameters
The name of the column in the database.