I would like to have PostgreSQL return the result of a query as one JSON array. Given
create table t (a int primary key, b text); insert into t values (1, \
Also if you want selected field from table and aggregated then as array .
SELECT json_agg(json_build_object('data_a',a, 'data_b',b, )) from t;
The result will come .
[{'data_a':1,'data_b':'value1'} {'data_a':2,'data_b':'value2'}]