JSON_ARRAY_INSERT
This function inserts values into a JSON document at a specified path, returning the modified document, and supports evaluating multiple path-value pairs sequentially.
Syntax
JSON_ARRAY_INSERT(json_doc, path, value[, path, value] ...)Description
Examples
SET @json = '[1, 2, [3, 4]]';
SELECT JSON_ARRAY_INSERT(@json, '$[0]', 5);
+-------------------------------------+
| JSON_ARRAY_INSERT(@json, '$[0]', 5) |
+-------------------------------------+
| [5, 1, 2, [3, 4]] |
+-------------------------------------+
SELECT JSON_ARRAY_INSERT(@json, '$[1]', 6);
+-------------------------------------+
| JSON_ARRAY_INSERT(@json, '$[1]', 6) |
+-------------------------------------+
| [1, 6, 2, [3, 4]] |
+-------------------------------------+
SELECT JSON_ARRAY_INSERT(@json, '$[1]', 6, '$[2]', 7);
+------------------------------------------------+
| JSON_ARRAY_INSERT(@json, '$[1]', 6, '$[2]', 7) |
+------------------------------------------------+
| [1, 6, 7, 2, [3, 4]] |
+------------------------------------------------+Last updated
Was this helpful?

