You need JSON functions like JSON_ARRAY_APPEND
see more functions to maniüulate.
Json needs some special function which have to be learned, we usually recomend nit to use JSON, because in a normalized table you can use all the sql functionality there exists,
JSON needs always a moderate learn effort
update myTable
set columnJson = '[{"id" : "someId1" , "name": "someNamme2"}
,{"id" : "someId2", "name": "someNamme2"}]'
where id = "rowID1";
Rows matched: 1 Changed: 1 Warnings: 0
update myTable
set columnJson = JSON_ARRAY_APPEND(columnJson, '$[0]', '{"id" : "someId3", "name": "someNamme3"}')
Rows matched: 1 Changed: 1 Warnings: 0
SELECT * FROM myTable
id |
columnJson |
rowID1 |
[[{"id": "someId1", "name": "someNamme2"}, "{"id" : "someId3", "name": "someNamme3"}"], {"id": "someId2", "name": "someNamme2"}] |
fiddle
And if you want another position you change te point where it shold change
update myTable
set columnJson = '[{"id" : "someId1" , "name": "someNamme2"}
,{"id" : "someId2", "name": "someNamme2"}]'
where id = "rowID1";
Rows matched: 1 Changed: 1 Warnings: 0
update myTable
set columnJson = JSON_ARRAY_APPEND(columnJson, '$[1]', '{"id" : "someId3", "name": "someNamme3"}')
Rows matched: 1 Changed: 1 Warnings: 0
SELECT * FROM myTable
id |
columnJson |
rowID1 |
[{"id": "someId1", "name": "someNamme2"}, [{"id": "someId2", "name": "someNamme2"}, "{"id" : "someId3", "name": "someNamme3"}"]] |
fiddle