Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL Json_modify function

T-Sql JSON_MODIFY function has some issue its adding wrapper when appending a new value pair like

  declare @jsonstring varchar(max) ='{"Width":"100%","Length":"45%"}'  
  select JSON_MODIFY(@jsonstring,'append $.Height ','50%' ) 

-- output {"Width":"100%","Length":"45%","Height":["50%"]}
-- Its adding wrapper i am unable to remove that wrapper
-- expecting output {"Width":"100%","Length":"45%","Height":"50%"}

like image 254
Kumar_2002 Avatar asked Dec 03 '25 15:12

Kumar_2002


1 Answers

Try this query:

declare @jsonstring varchar(max) ='{"Width":"100%","Length":"45%"}'  
select JSON_MODIFY(@jsonstring,'$.Height ','50%' ) 

The documentation for append says:

"Optional modifier that specifies that the new value should be appended to the array referenced by < json path >."

like image 147
Razvan Socol Avatar answered Dec 05 '25 13:12

Razvan Socol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!