Rechercher dans le manuel MySQL
12.17.2 Functions That Create JSON Values
The functions listed in this section compose JSON values from component elements.
Evaluates a (possibly empty) list of values and returns a JSON array containing those values.
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.- +-----------------------------------------+
- | JSON_OBJECT('id', 87, 'name', 'carrot') |
- +-----------------------------------------+
- | {"id": 87, "name": "carrot"} |
- +-----------------------------------------+
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. ReturnsNULL
if the argument isNULL
.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.22, “JSON_UNQUOTE() Special Character Escape Sequences”.
- +--------------------+----------------------+
- | JSON_QUOTE('null') | JSON_QUOTE('"null"') |
- +--------------------+----------------------+
- | "null" | "\"null\"" |
- +--------------------+----------------------+
- +-------------------------+
- | 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(
; see
Converting between JSON and non-JSON values, for more
information.
value
AS
JSON)
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 (GROUP BY) Functions”.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-json-creation-functions.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.