Outdated Version

You are viewing an older version of this section. View current production version.

JSON_DELETE_KEY

Removes a named key and value from a JSON map or array. Maps are in the form:

{"a": 1, "b": 2, "c": 3}
JSON_DELETE_KEY(json, keypath)

Arguments

  • json: a JSON value
  • keypath: the path to the key to delete (comma-separated list of dictionary keys or zero-indexed array positions).

Return Value

  • The record without the key.
  • SQL NULL if json is not a valid JSON.

Examples

mysql> select json_delete_key('{"a": 1, "b": 2, "c": 3}', 'a') as del;
+---------------+
| del           |
+---------------+
| {"b":2,"c":3} |
+---------------+

mysql> select json_delete_key('{"a": 1, "b": 2, "c": 3}', 'z') as nochange;
+---------------------+
| nochange            |
+---------------------+
| {"a":1,"b":2,"c":3} |
+---------------------+

mysql> select json_delete_key ('{"a":[1,2,3]}','a', 1) as array_delete;
+--------------+
| array_delete |
+--------------+
| {"a":[1,3]}  |
+--------------+