Skip to content

json_group_array ​

Collects input values into a JSON text array. SQL NULL becomes a JSON null element. Text values are quoted as JSON strings; use json(value) to parse JSON text before including it as a structured value.

Syntax

text
json_group_array(value [ORDER BY expression])

Arguments

  • value — One SQL value per row. Binary blobs are rejected.

DISTINCT, FILTER, aggregate ordering, and ordinary window calls are supported.

Returned value

A JSON text array. Empty input returns []. The related json_agg returns NULL for empty input.

Examples

sql
CREATE TABLE readings (value Int32);
INSERT INTO readings VALUES (1), (NULL), (3);
sql
SELECT json_group_array(value ORDER BY rowid) FROM readings FORMAT csv;
text
"[1,null,3]"
sql
SELECT json_group_array(value) FROM readings WHERE value > 100 FORMAT csv;
text
"[]"