Purpose
JSON_REMOVE() removes data from a JSON document and returns the results.
Syntax
JSON_REMOVE(json_doc, path[, path] ...)
Description
json_doc specifies the name of the JSON document, and path specifies the path. If any argument is NULL, the return value is NULL.
An error occurs in the following cases:
The JSON document specified for
json_docis invalid.The path expression specified for
pathis invalid.pathis set to$.The specified
pathcontains a * or ** wildcard.
The path-value pairs are evaluated from left to right. The document produced by evaluating one path-value pair becomes the new value against which the next pair is evaluated.
If the element to be removed does not exist in the document, no error will occur. 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