I am struggling to find a way to update specific JSON objects in a array within JSON-type field in MySQL. Let's say I have the following object:
SET @j = '{
"cat": "meow",
"dog": "woof",
"parrot": [
{"volume": "quiet", "says": "hello"},
{"volume": "loud", "says": "polly"},
{"volume": "loud", "says": "cracker"}
]
}';
How can I update all objects in the parrot array that have the volume value as loud?
I know I could use the JSON_SET or JSON_REPLACE functions to change/update a specific object if the position of the object is known. For example something like:
UPDATE T1 SET @J = JSON_SET(@j, '$.parrot[1].says', 'pretty bird');
However I don't know the positions of the objects and also this doesn't update all in the parrot array that have the volume value as loud?
Any suggestions?