• JSON_QUOTE( string ) 

Quotes a string as a JSON value by wrapping it with double quote characters and escaping interior quote and other characters, then returning the result as a utf8mb4  string. Returns NULL  if the argument is NULL . 

This function is typically used to produce a valid JSON string literal for inclusion within a JSON document. 

Certain special characters are escaped with backslashes per the escape sequences shown in Table 12.23, “JSON_UNQUOTE() Special Character Escape Sequences” . 

mysql> SELECT JSON_QUOTE(’null’), JSON_QUOTE(’"null"’); +--------------------+----------------------+ | JSON_QUOTE(’null’) | JSON_QUOTE(’"null"’) | +--------------------+----------------------+ | "null" | ""null"" | +--------------------+----------------------+ mysql> SELECT JSON_QUOTE(’[1, 2, 3]’); +-------------------------+ | JSON_QUOTE(’[1, 2, 3]’) | +-------------------------+ | "[1, 2, 3]" | +-------------------------+ 

You can also obtain JSON values by casting values of other types to the JSON  type using CAST( value AS JSON) ; see Converting between JSON and non-JSON values, for more information. 

Two aggregate functions generating JSON values are available. JSON_ARRAYAGG()  returns a result set as a single JSON array, and JSON_OBJECTAGG()  returns a result set as a single JSON object. For more information, see Section 12.20, “Aggregate Functions” . 

## 12.18.3 Functions That Search JSON Values 

The functions in this section perform search or comparison operations on JSON values to extract data from them, report whether data exists at a location within them, or report the path to data within them. The MEMBER OF()  operator is also documented herein. 

• JSON_CONTAINS( target , candidate [, path ]) 

Indicates by returning 1 or 0 whether a given candidate  JSON document is contained within a target JSON document, or—if a path  argument was supplied—whether the candidate is found at a specific path within the target. Returns NULL  if any argument is NULL , or if the path argument does not identify a section of the target document. An error occurs if target  or candidate  is not a valid JSON document, or if the path  argument is not a valid path expression or contains a *  or **  wildcard. 

To check only whether any data exists at the path, use JSON_CONTAINS_PATH()  instead. 

The following rules define containment: 

•A candidate scalar is contained in a target scalar if and only if they are comparable and are equal. Two scalar values are comparable if they have the same JSON_TYPE()  types, with the exception that values of types INTEGER  and DECIMAL  are also comparable to each other. 

•A candidate array is contained in a target array if and only if every element in the candidate is contained in some element of the target. 

•A candidate nonarray is contained in a target array if and only if the candidate is contained in some element of the target. 

