Description
This function is used to delete data from a JSON document and return the result.
Syntax
JSON_REMOVE(json_doc, path[, path] ...)
Description
The json_doc parameter specifies the JSON document, and path is a path parameter. If either parameter is NULL, NULL is returned.
An error occurs in the following scenarios:
The
json_docparameter is not a valid JSON document.The
pathparameter is not a valid path expression.The
pathparameter is$.The
pathparameter contains the * or ** wildcard.
The path parameter is evaluated from left to right. That is, the document generated by evaluating one path is used as the new value for evaluating the next path.
If the element to be removed does not exist in the document, no error is generated. In this case, the path does not affect the document.
Examples
obclient> SET @jn = '["a", ["b", "c"], "d"]';
Query OK, 0 rows affected
obclient> SELECT JSON_REMOVE(@jn, '$[1]');
+--------------------------+
| JSON_REMOVE(@jn, '$[1]') |
+--------------------------+
| ["a", "d"] |
+--------------------------+
1 row in set
obclient> SELECT JSON_REMOVE(@jn, '$[7]');
+--------------------------+
| JSON_REMOVE(@jn, '$[7]') |
+--------------------------+
| ["a", ["b", "c"], "d"] |
+--------------------------+
1 row in set