content_image/723529.jpg content_image/723532.jpg content_image/723535.jpg content_image/723536.jpg
<img src='content_image/723529.jpg'>

4 rows in set (0.00 sec) 

mysql> SELECT o_id, JSON_ARRAYAGG(attribute) AS attributes > FROM t3 GROUP BY o_id; 

<img src='content_image/723532.jpg'>

2 rows in set (0.00 sec) 

• JSON_OBJECTAGG( key , value ) [ over_clause ] 

Takes two column names or expressions as arguments, the first of these being used as a key and the second as a value, and returns a JSON object containing key-value pairs. Returns NULL  if the result contains no rows, or in the event of an error. An error occurs if any key name is NULL  or the number of arguments is not equal to 2. 

As of MySQL 8.0.14, this function executes as a window function if over_clause  is present. over_clause  is as described in Section 12.21.2, “Window Function Concepts and Syntax” . 

mysql> SELECT o_id, attribute, value FROM t3; 

<img src='content_image/723535.jpg'>

4 rows in set (0.00 sec) 

mysql> SELECT o_id, JSON_OBJECTAGG(attribute, value) > FROM t3 GROUP BY o_id; 

<img src='content_image/723536.jpg'>

2 rows in set (0.00 sec) 

Duplicate key handling.  When the result of this function is normalized, values having duplicate keys are discarded. In keeping with the MySQL JSON  data type specification that does not permit duplicate keys, only the last value encountered is used with that key in the returned object (“last duplicate key wins” ). This means that the result of using this function on columns from a SELECT  can depend on the order in which the rows are returned, which is not guaranteed. 

When used as a window function, if there are duplicate keys within a frame, only the last value for the key is present in the result. The value for the key from the last row in the frame is deterministic if the ORDER BY  specification guarantees that the values have a specific order. If not, the resulting value of the key is nondeterministic. 

Consider the following: 

