How can I get question_id field in this json file? I tried, but it returns null.
DECLARE @json NVARCHAR(MAX)
SET @json =
N'{
"solution": "xxxxxxxxxxxxxxxxxxxxx",
"options": [
{
"choice_id": 205073,
"choice": "aaaa"
},
{
"choice_id": 205074,
"choice": "bbbb"
},
{
"choice_id": 205075,
"choice": "cccc"
},
{
"choice_id": 205076,
"choice": "dddd"
}
],
"question_id": 12345
}'
SELECT * FROM
OPENJSON ( @json, '$.options')
WITH (
choice_id varchar(8000) '$.choice_id',
question_id int '$.question_id'
)
Result