This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- JSON_VALUE Demonstration to pull one scalar value from the JSON data | |
DECLARE @json nvarchar(max) | |
SET @json =N' | |
{ | |
"Person": [ | |
{ | |
"FirstName": "Gustavo", | |
"LastName": "Harris", | |
"AccountNumber": "AW00029484", | |
"ModifiedDate": "2014-09-12T11:15:07.263" | |
}, | |
{ | |
"FirstName": "Catherine", | |
"LastName": "Abel", | |
"AccountNumber": "AW00029485", | |
"ModifiedDate": "2014-09-12T11:15:07.263" | |
} | |
] | |
}' | |
-- Extract scalar value from a JSON text | |
SELECT JSON_VALUE(@json, '$.Person[0].LastName'); | |
SELECT JSON_VALUE(@json, '$.Person[1].AccountNumber'); | |
-- Returns NULL if the path does not exist | |
SELECT JSON_VALUE(@json, '$.Person[1].Age'); | |
-- lax option is by default and returns NULL if there is a problem | |
SELECT JSON_VALUE(@json, 'lax $.Person[1].Age'); | |
-- strict option raises an error if there is a problem | |
SELECT JSON_VALUE(@json, 'strict $.Person[1].Age'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment