JSON_REPLACE(json_doc, jalur, val[, jalur, val] ...)
SET @j = '{ "a": 1, "b": [2, 3]}';
SELECT JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]');
+-----------------------------------------------------+
| JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]') |
+-----------------------------------------------------+
| {"a": 10, "b": [2, 3]} |
+-----------------------------------------------------+
SELECT JSON_REPLACE(NULL, '$.a', 10, '$.c', '[true, false]');
+-------------------------------------------------------+
| JSON_REPLACE(NULL, '$.a', 10, '$.c', '[true, false]') |
+-------------------------------------------------------+
| NULL |
+-------------------------------------------------------+
SELECT JSON_REPLACE(@j, NULL, 10, '$.c', '[true, false]');
+----------------------------------------------------+
| JSON_REPLACE(@j, NULL, 10, '$.c', '[true, false]') |
+----------------------------------------------------+
| NULL |
+----------------------------------------------------+
SELECT JSON_REPLACE(@j, '$.a', NULL, '$.c', '[true, false]');
+-------------------------------------------------------+
| JSON_REPLACE(@j, '$.a', NULL, '$.c', '[true, false]') |
+-------------------------------------------------------+
| {"a": null, "b": [2, 3]} |
+-------------------------------------------------------+
Replaces existing values in a JSON document and returns the result. Returns NULL if json_doc or any path argument is NULL. An error occurs if the json_doc argument is not a valid JSON document or any path argument is not a valid path expression or contains a * or ** wildcard.
SET @j = '{ "a": 1, "b": [2, 3]}';
SELECT JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]');
+-----------------------------------------------------+
| JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]') |
+-----------------------------------------------------+
| {"a": 10, "b": [2, 3]} |
+-----------------------------------------------------+
SELECT JSON_REPLACE(NULL, '$.a', 10, '$.c', '[true, false]');
+-------------------------------------------------------+
| JSON_REPLACE(NULL, '$.a', 10, '$.c', '[true, false]') |
+-------------------------------------------------------+
| NULL |
+-------------------------------------------------------+
SELECT JSON_REPLACE(@j, NULL, 10, '$.c', '[true, false]');
+----------------------------------------------------+
| JSON_REPLACE(@j, NULL, 10, '$.c', '[true, false]') |
+----------------------------------------------------+
| NULL |
+----------------------------------------------------+
SELECT JSON_REPLACE(@j, '$.a', NULL, '$.c', '[true, false]');
+-------------------------------------------------------+
| JSON_REPLACE(@j, '$.a', NULL, '$.c', '[true, false]') |
+-------------------------------------------------------+
| {"a": null, "b": [2, 3]} |
+-------------------------------------------------------+