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

MySQL supports two aggregate JSON functions JSON_ARRAYAGG()  and JSON_OBJECTAGG() . See Section 12.20, “Aggregate Functions” , for descriptions of these. 

MySQL also supports “pretty-printing”  of JSON values in an easy-to-read format, using the JSON_PRETTY()  function. You can see how much storage space a given JSON value takes up, and how much space remains for additional storage, using JSON_STORAGE_SIZE()  and JSON_STORAGE_FREE() , respectively. For complete descriptions of these functions, see Section 12.18.8, “JSON Utility Functions” . 

## 12.18.2 Functions That Create JSON Values 

The functions listed in this section compose JSON values from component elements. 

• JSON_ARRAY([ val [, val ] ...]) 

Evaluates a (possibly empty) list of values and returns a JSON array containing those values. 

mysql> SELECT JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME()); +---------------------------------------------+ | JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME()) | +---------------------------------------------+ | [1, "abc", null, true, "11:30:24.000000"] | +---------------------------------------------+ 

• JSON_OBJECT([ key , val [, key , val ] ...]) 

Evaluates a (possibly empty) list of key-value pairs and returns a JSON object containing those pairs. An error occurs if any key name is NULL  or the number of arguments is odd. 

mysql> SELECT JSON_OBJECT(’id’, 87, ’name’, ’carrot’); +-----------------------------------------+ | JSON_OBJECT(’id’, 87, ’name’, ’carrot’) | +-----------------------------------------+ | {"id": 87, "name": "carrot"} | +-----------------------------------------+ 

