jsonb_agg
Aggregate values into a canonical native JSON array.
Syntax
text
jsonb_agg(value [ORDER BY ...])Arguments
Includes NULL as JSON null; canonicalizes nested objects. FILTER, DISTINCT and ordinary windows apply. Retains encoded values; repeated finalization preserves state.
Returned value
Native JSON array, or SQL NULL for an empty input.
Examples
sql
CREATE TABLE readings (value INTEGER);
INSERT INTO readings VALUES (1),(NULL),(2);sql
SELECT jsonb_agg(value) FROM readings FORMAT csv;text
"[1,null,2]"