I have json string in sql db as this
{
"MainItem":{
"UserId":4,
"UserName":"name",
"CityDetails":{
"CityId":1,
"CityName":"egypt"
},
"ListSubItems":[
{
"UserId":2,
"UserName":"name2",
"FullDescription":"",
"ShortDescription":"wish",
"CityDetails":{
"CityId":2,
"CityName":"us"
}
},
{
"UserId":3,
"UserName":"name3",
"FullDescription":"",
"ShortDescription":"wish",
"CityDetails":{
"CityId":44,
"CityName":"sau"
}
}
]
}
}
you can parse on https://jsonparseronline.com/ to view json
I need to update $.MainItem.ListSubItems where UserId=3 set UserName ='new name'
I need update all userid = 3
as
update MyTable
set jsonCol= json_modify(jsonCol, $.MainItem.ListSubItems .where userId=3 , userName='new name ')