I have a table with the following structure/rows:
ID | OptionName | OptionValue |
---|---|---|
0 | Gender | Male |
1 | Gender | Female |
I want to query the database and return the following JSON:
[{
"OptionName":"Gender",
"Values":[
"Male",
"Female"
]
}]
However the result I'm currently getting is this:
[{
"OptionName":"Gender",
"Values":[
{
"OptionValue":"Male"
},
{
"OptionValue":"Female"
}
]
}]
Here is my Query:
SELECT TOP(1) OptionName,
(
JSON_QUERY(
(
SELECT OptionValue
FROM [TestJSON].[dbo].[Options]
WHERE OptionName = 'Gender'
FOR JSON PATH
)
)
) AS [Values]
FROM [TestJSON].[dbo].[Options]
WHERE OptionName = 'Gender'
FOR JSON PATH
What can I do to get the result I need?