Skip to content

JSON_ARRAYAGG

  • col_or_expr: This parameter refers to the column or the expression to be transformed into a JSON array. JSON_ARRAYAGG(col_or_expr) collects values from each row, encapsulating the value of the selected column or expression into a JSON array.
SELECT JSON_ARRAYAGG(customer_name) as customerList
FROM customers;
{
"customerList": ["John Doe", "Jane Smith", "Tom Brown"]
}

The JSON_ARRAYAGG function is used to convert a group of rows into a JSON array. In the example, it is converting the list of “customer_name” from the “customers” table into a JSON array named “customerList”.