I would like to insert new values into a random Json string without using the Json_modify function. I am using SQL Server 2016.
For example, let's say I have a Json string like this:
{ "a": { "b": "val"} }
Now I would like to add a new object into the Json string. After adding a object c with value NEW the Json string should look like this:
{ "a": { "b": "val", "c": "NEW"} }
Is there any way to do something like this without using json_modify?
I do not want to save the Json string into a table. All I want afterwards is a SQL Server procedure which adds a Json object into a Json string on a defined position.
Thanks
How I'd do this with JSON_MODIFY:
declare @jsonString nvarchar(4000) = '{"a": {"b":"val"} }'
, @jsonResult nvarchar(4000)
, @path nvarchar(128) = '$.a.c'
, @value nvarchar(128) = 'NEW'
set @jsonResult = JSON_MODIFY(@jsonString, @path, @value)
select @jsonResult
json_modify, do you mean you want to use string manipulation instead / what's your reason for not usingjson_modify?