I have below json in sql:
declare @jObject as nvarchar(max)='{
"StudentData": [
{
"StudentID":5000,
"StudentName":"xyz"
},
{
"StudentID":5001,
"StudentName":"abc"
}
]
}'
I want to write select query such that :-
StudentID StudentName
5000 xyz
5001 abc
I tried below query :-
SELECT *
FROM OPENJSON(@jObject)
WITH (StudentID int '$.StudentID',StudentName varchar(50) '$.StudentName')
But this is returning me single row and null values for both columns. Please help.
Also tried below which is not working :-
EDIT 1 :-
SELECT *
FROM OPENJSON(@jObject)
WITH (StudentID int '$.StudentData.StudentID',StudentName varchar(50) '$.StudentData.StudentName')
StudentID, ` StudentName` properties. Try'$.StudentData.StudentID'