HI WELCOME TO KANSIRIS

JSON_MODIFY Function in Sql Server 2016

Leave a Comment
JSON_MODIFY Function: It update the value of the property in a JSON string and returns the updated JSON string. 

SYNTAX: JSON_MODIFY (inputJSONstring, json_path , update_value)

json_string : It is JSON String which need to be updated
json_path : It is location of the property in the inputJSONstring, whose value needs to be updated
update_value : The new value for the property in the inputJSONstring

EXAMPLE 1:  Updating JSON Property Value

DECLARE @inputJSONstring NVARCHAR(MAX) = '{"ENAME":"ALOK","JOB":"ADMIN"}'
SELECT JSON_MODIFY(@inputJSONstring,'$.JOB','Developer') AS 'MODIFY_JSON'

OUTPUT:-

MODIFYED_JSON
{"ENAME":"ALOK","JOB":"Developer"}

  
EXAMPLE 1:   we can append a value to the JSON Array.

SELECT JSON_MODIFY('{"ENAME":"ALOK","JOB":"ADMIN"}',
             'append $.Sites','www.code-view.com, www.code-sample.com, www.code-sample.xyz') AS 'Updated JSON'

OUTPUT:-

Updated JSON

{"ENAME":"ALOK","JOB":"ADMIN","Sites":["www.code-view.com,www.code-sample.com,www.code-sample.xyz"]}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.