I Have this json:
{"keyvalue": {"head": {"id": ""},"column": {"id": ""},"degrees": {"id": ""}}}
How do i add this json to the key "keyvalue":
"somekey": { "id" : "" }
so my json looks like this:
{"keyvalue": {"head": {"id": ""},"column": {"id": ""},"degrees": {"id": ""}, "somekey": { "id" : "" }}}
i tried this:
SELECT JSON_MODIFY('{"keyvalue": {"head": {"id": ""},"column": {"id": ""},"degrees": {"id": ""}}}', 'append $', json_query(N' {"somekey": {"id" : ""}}'))
FROM PL_Table
WHERE PL_Id = 6;
but nothing changed
UPDATE
i have this now:
update PL_PageLayout
set PL_Json = json_modify('{
"keyvalue": {
"obj1": {
"id": ""
},
"obj2": {
"id": ""
},
"obj3": {
"id": ""
}
}
}', 'append $.keyvalue.content', '{"id" : "ddd"}')
FROM PL_PageLayout
WHERE PL_Id = 6;
Output is:
{"keyvalue": {"obj1": {"id": ""},"obj2": {"id": ""},"obj3": {"id": ""},"content":["{\"id\" : \"ddd\"}"]}}
but the
"content":["{\"id\" : \"ddd\"}"]
needs to be
"content":{\"id\" : \"ddd\"}
PL_Table? A SELECT query won't do that. You have to use an UPDATE.