Is that possible in SQL Server JSON to update elements with a certain attribute value regardless root, position and nesting level?
For example we have multiple elements like
{ "name": "target_name", "value": 123 }
They can appear on any level within a random json string, so is that possible to increment value
number for elements with target_name
?
Thanks!
PS: we can't install any DB extensions due to Azure limitations, so it should be done using native SQL.
UPD: JSON example:
{
"name": "target_name",
"value": 1,
"some_arr": [
{
"foo": "foo",
"name": "foo_name"
},
{
"name": "target_name",
"value": 5
},
{
"foo2": "foo",
"name": "some_name"
"foo3": {
"name": "target_name",
"value": 7
}
}
]
}
In this example there are three elements with name=="target_name", they are placed as root, in an array, on a deeper nesting level. JSON structure can change. The point is to increment numbers 1, 5, and 7 within "value" attributes using standard means like JSON_MODIFY
, OPENJSON
, JSON_VALUE
.