Purpose
This function deletes data from a JSON document and returns the result.
Syntax
JSON_REMOVE(json_doc, path[, path] ...)
Considerations
The json_doc parameter specifies the JSON document, and path specifies the path. 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 is$.The
pathparameter contains the * or ** wildcard.
The path parameter is evaluated from left to right. 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
