json_modify SQL Server

/*
1. Updates the value of a property in a JSON string and returns the 
updated JSON string.
2. SON_MODIFY returns an error if expression doesn't contain valid JSON.
*/

DECLARE @info NVARCHAR(100)='{"name":"John","skills":["C#","SQL"]}'
PRINT @info -- resutl : {"name":"John","skills":["C#","SQL"]}

-- Update name  
SET @info=JSON_MODIFY(@info,'$.name','Mike')
PRINT @info -- result: {"name":"Mike","skills":["C#","SQL"]}

-- add id
SET @info=JSON_MODIFY(@info,'$.id',1)
PRINT @info -- {"name":"Mike","skills":["C#","SQL"],"id":1}
Tiny Coders