Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samirbehara-zz/f835ccb13a17ae78ba40b47a5cb0b46b to your computer and use it in GitHub Desktop.
Save samirbehara-zz/f835ccb13a17ae78ba40b47a5cb0b46b to your computer and use it in GitHub Desktop.
-- JSON_MODIFY Demonstration to update the value of a property in JSON string
DECLARE @json nvarchar(max)
SET @json =N'
{
"Person": [
{
"Name": {
"FirstName": "Catherine",
"LastName": "Abel"
},
"Address": {
"State": "VA",
"Zip": "24153"
}
}
]
}'
PRINT @json
IF (ISJSON(@json) = 1)
PRINT 'It is a Valid JSON' --Valid JSON
ELSE
PRINT 'It is an Invalid JSON string'
PRINT JSON_MODIFY (@json, '$.Person[0].Address.Zip' , '35043');
PRINT @json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment