I am using MySQL 8 and trying to update JSON data type in a mysql table
My table t1 looks as below:
# id key value
1100000 key123 [{"name": "name1", "hosts": ["host123"]}]
Now, I have a list of hosts hostlist as below:
SET @hostlist = '["host343", "host345"]';
I want to append @hostlist to the hosts array within value JSON Array:
UPDATE table t1
SET t1.value = JSON_ARRAY_APPEND('[]', '$', JSON_OBJECT('hosts', @hostlist))
WHERE t1.key = 'key123';
Desired Output:
[{"name": "name1", "hosts": ["host123","host343", "host345"]}]