Skip to main content
Version: V1.0.0

JSON_REMOVE

Description

This function removes data from a JSON document and returns the result.

Syntax

JSON_REMOVE(json_doc, path[, path] ...)

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_doc parameter is not a valid JSON document.

  • The path parameter is not a valid path expression.

  • The path parameter is $.

  • The path parameter 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

SET @jn = '["a", ["b", "c"], "d"]';
Query OK, 0 rows affected (0.000 sec)

SELECT JSON_REMOVE(@jn, '$[1]');
+--------------------------+
| JSON_REMOVE(@jn, '$[1]') |
+--------------------------+
| ["a", "d"] |
+--------------------------+
1 row in set (0.001 sec)

SELECT JSON_REMOVE(@jn, '$[7]');
+--------------------------+
| JSON_REMOVE(@jn, '$[7]') |
+--------------------------+
| ["a", ["b", "c"], "d"] |
+--------------------------+
1 row in set (0.001 sec)