T-SQL Json_modify function

Viewed 109

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%"}

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 >."

Related