Example: Using JSON_AGG with GROUP BY and with All Parameter Names

Teradata Vantageā„¢ JSON Data Type

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1150-162K
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}]