JSON_REPLACE
Description
This function replaces existing values in a JSON document and returns the result.
Syntax
JSON_REPLACE(json_doc, path, val[, path, val] ...)
Description
The json_doc parameter specifies the JSON document, and path is the path parameter. If any parameter is NULL, the function returns NULL.
The following situations will result in an error:
-
The
json_docparameter is not a valid JSON document. -
The
pathparameter is not a valid path expression. -
The
pathparameter contains the * or ** wildcard.
Path-value pairs are evaluated from left to right. The document generated by each path-value pair is used as the new value for the next pair.
Existing path-value pairs in the document will be overwritten by the new values. Path-value pairs that do not exist in the document will be ignored and considered invalid.
Examples
SET @jn = '{ "a": 1, "b": [2, 3, 4]}';
Query OK, 0 rows affected (0.000 sec)
SELECT JSON_REPLACE(@jn, '$.a', 10, '$.c', '[true, false]');
+------------------------------------------------------+
| JSON_REPLACE(@jn, '$.a', 10, '$.c', '[true, false]') |
+------------------------------------------------------+
| {"a": 10, "b": [2, 3, 4]} |
+------------------------------------------------------+
1 row in set (0.001 sec)