JSON_OBJECT

Creates a new JSON object from a variable number of name-value pairs.

This function constructs a JSON object from the provided nameValue pairs. Each pair consists of a string name (key) and a value. The values can be any of the supported Kotlin types which are then converted into their corresponding JSON representations (null, boolean, number, or string). KQLiteColumn instances can also be passed as values.

If no arguments are provided, it returns an empty JSON object {}. If a name is repeated, only the last value for that name is used.

Example:

// SELECT JSON_OBJECT('a', 2, 'c', 4);
// Result: '{"a":2,"c":4}'
select(JSON_OBJECT("a" to 2, "c" to 4)).execute()

// Example with a column value
val nameCol = textColumn("name")
val ageCol = intColumn("age")

// SELECT JSON_OBJECT('name', name, 'age', age) FROM MyTable;
// Result for a row with name='John' and age=30: '{"name":"John","age":30}'
select(JSON_OBJECT("name" to nameCol, "age" to ageCol)).from(MyTable).execute()

// SELECT JSON_OBJECT();
// Result: '{}'
select(JSON_OBJECT()).execute()

Return

A KQLiteJsonObject representing the newly created JSON object.

Author

MOHAMMAD AZIM ANSARI

Parameters

nameValue

A variable number of Pairs, where each pair represents a key-value mapping for the JSON object.

See also