Utilice json_agg()
para obtener una matriz:
SELECT json_agg(source_column) AS the_column
FROM tbl;
O json_each()
en un LATERAL
unirse y json_object_agg()
ensamblar elementos:
SELECT json_object_agg(key, value) AS the_column
FROM tbl, json_each(data);