The example shows how to use JSON_Agg to assign parameter names in the resulting JSON instance and use the GROUP BY clause.
SELECT JSON_agg(empID AS id, empName AS name, empAge AS age) FROM emp_table GROUP BY company;
Result: The query returns one line of output (note, output line is wrapped).
JSON_agg(empID AS id,empName AS name,empAge AS age) --------------------------------------------------- [{"id":3,"name":"Someone","age":24}, {"id":1,"name":"Cameron","age":24}, {"id":2,"name":"Justin","age":34}]