Example: Use JSON_COMPOSE to Extract Values from a Table and Compose a JSON Object - Advanced SQL Engine - Teradata Database

JSON Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
gzn1554761068186.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1150
lifecycle
previous
Product Category
Teradata Vantageā„¢
Use JSON_COMPOSE to create a JSON object from the values selected from a table.
SELECT JSON_Compose(T.company, T.employees)
FROM
 (
  SELECT company, JSON_agg(empID AS id, 
     empName AS name, 
     empAge AS age) AS employees
  FROM emp_table
  GROUP BY company
 ) AS T;
Result:
JSON_Compose
------------
{
  "company" : "Teradata",
  "employees" : [ 
     { "id" : 1, "name" : "Cameron", "age" : 24 },
     { "id" : 2, "name" : "Justin", "age" : 34 }
  ]
}
{
  "company" : "Apple",
  "employees" : [ 
     { "id" : 3, "name" : "Someone", "age" : 24 } 
  ]
}