add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
SET @json := '{"k1":[{"id":1,"name":"guna","age":34},
{"id":2,"name":"guna1","age":34},
{"id":3,"name":"guna2","age":34}]}';
SET @replacement := '{"id":1,"name":"guna","age":34,"hi":"hi"}';
SELECT JSON_OBJECT('k1', JSON_ARRAYAGG(CAST(object AS JSON)))
FROM ( SELECT COALESCE(replacement, object) object
FROM JSON_TABLE(@json,
'$.k1[*]' COLUMNS (rowid FOR ORDINALITY,
object JSON PATH '$')) jsontable
LEFT JOIN (SELECT @replacement replacement) replacement
ON object->'$.id' = replacement->'$.id'
ORDER BY rowid ASC LIMIT 2147483647) reconstruction;
JSON_OBJECT('k1', JSON_ARRAYAGG(CAST(object AS JSON)))
{"k1": [{"hi": "hi", "id": 1, "age": 34, "name": "guna"}, {"id": 2, "age": 34, "name": "guna1"}, {"id": 3, "age": 34, "name": "guna2"}]}