JSON_GROUP_ARRAY

An aggregate function that returns a JSON array containing all values from the specified column within a group.

This function operates on a set of rows (defined by a GROUP BY clause, or all rows if not specified) and aggregates the values from the given column into a single JSON array. The order of elements in the resulting array is arbitrary.

NULL values in the input column are included as JSON null literals in the output array.

Example:

// Assuming 'Products' table has a 'name' column
val nameCol = textColumn("name")

// Aggregate all product names into a single JSON array.
// SELECT JSON_GROUP_ARRAY(name) FROM Products;
// Result might be: '["Laptop","Mouse","Keyboard"]'
select(JSON_GROUP_ARRAY(nameCol)).from(Products).execute()

// Group by category and aggregate names
val categoryCol = textColumn("category")
// SELECT category, JSON_GROUP_ARRAY(name) FROM Products GROUP BY category;
select(categoryCol, JSON_GROUP_ARRAY(nameCol)).from(Products).groupBy(categoryCol).execute()

Return

A KQLiteJsonArray representing the aggregated JSON array.

Author

MOHAMMAD AZIM ANSARI

Parameters

column

The column whose values are to be aggregated into the JSON array.

See also