I have this so far, and it removes only one object, and there are 4 that should be removed.
SET @JSON = '[{"one": 5},{"two":2},{"one": 5},{"three":3},{"one": 5},{"one": 5}]';
SET @TO_REMOVE = '{"one": 5}';
SET @JSON = REPLACE(@JSON, @TO_REMOVE, '"DELETED"');
SET @JSON = JSON_REMOVE(@JSON, JSON_UNQUOTE(JSON_SEARCH(@JSON, 'one', 'DELETED')));
SELECT @JSON;
#returns the following:
[{"two": 2}, "DELETED", {"three": 3}, "DELETED", "DELETED"]
What I really want is a method like the above, but instead of putting in 'one' in JSON_SEARCH I want to put 'all'. Does anyone know how to do this?
SELECT JSON_UNQUOTE(JSON_SEARCH(@JSON, 'one', 'DELETED')) AS `Single`; #returns: $[0]
SELECT JSON_UNQUOTE(JSON_SEARCH(@JSON, 'all', 'DELETED')) AS `Multi`; #returns: ["$[0]", "$[2]", "$[4]", "$[5]"]
Is there a way to pass in each value ["$[0]", "$[2]", "$[4]", "$[5]"]
into JSON_REMOVE, like you have ...
in JavaScript for function arguements.
Thanks, please let me know alternative methods as well.