Reference Guide > TDV Support for SQL Functions > TDV-Supported JSON Functions > JSON_OBJECTAGG
 
JSON_OBJECTAGG
Constructs an aggregation object member for each key-value pair and returns a single JSON object that contains those object members
Syntax
<JSON object aggregate constructor> ::= “JSON_OBJECTAGG” “(“ <JSON name> “,” <JSON value expression> [ "NULL ON NULL" | "ABSENT ON NULL" ] ] “)”
Rules
1. Return type is String;
2. NULL ON NULL is implicit;
3. Return null if cardinality of output is 0;
4. Add option to control, whether to throw exception if name is null, or replace the name with empty string, or ignore null keys, should not throw exception by default. (Using the same option with 2.3.1.1);
5. Add option to control whether to handle duplicate key. (RFC7159 do not allow duplicate keys) (Using the same option with 2.3.1.1);
6. Besides numeric, boolean, null types, JSON values should be string or cast as string.
Examples
SELECT JSON_OBJECTAGG(customerid, 'ID') a1 FROM /shared/examples/ds_orders/tutorial/customers GROUP BY customerid HAVING JSON_OBJECTAGG(customerid, 'ID')='{}'