Chadrick Blog

convert subquery columns into array of json objects

SELECT json\_agg(t) FROM t
for a JSON array of objects, and

SELECT
    json\_build\_object(
        'a', json\_agg(t.a),
        'b', json\_agg(t.b)
    )
FROM t