Many have this problem, however it's usually because the JSON is incorrect. Can anyone tell me why this does not work. I expect to get a result set of:
ONE FirstName LastName
1 John Smith
Instead, I get an empty result set and the following error message in SSMS:
Msg 13609, Level 16, State 2, Line 20
JSON text is not properly formatted. Unexpected character 'J' is found at position 0.
DECLARE @IN_JSON NVARCHAR(MAX) =
N'{
"resume": {
"mailAddress": {
"sectionOrder": 10,
"section": {
"firstName": "John",
"lastName": "Smith"
}
}
}
}'
SELECT '1' AS [One],
JSON_VALUE(a.value, '$.firstName') AS [FirstName],
JSON_VALUE(a.value, '$.lastName') AS [LastName]
FROM OPENJSON (@IN_JSON, '$.resume.mailAddress.section') AS a