Skip to content

json_agg ​

Collect group inputs, including NULL, into a JSON array.

Syntax

text
json_agg(value)

Arguments

One SQL expression per row, converted to a JSON value. FILTER, DISTINCT, ordering and windows are supported.

Returned value

JSON-tagged TEXT array, or NULL when no input row exists.

Examples

sql
CREATE TABLE readings (value INTEGER);
INSERT INTO readings VALUES (1),(NULL),(2);
sql
SELECT json_agg(value) FROM readings FORMAT csv;
text
"[1,null,2]"