From the following query I am getting result as :
"Units": "[{\"Name\":\"Unit25\"}]",
Query is as follow query which reproducing this result, I have simplified the query actual query is used but based selection is this:
SELECT (
SELECT *
FROM (
SELECT
JSON_QUERY(COALESCE((SELECT [Name] FROM (
SELECT [Name]
FROM [TableA]
UNION
SELECT TOP 3 [Name]
FROM [TableB]) [T]
FOR JSON PATH),'[]')) AS [Units]
FROM [User] [U]
UNION
SELECT
JSON_QUERY(COALESCE((SELECT [Name] FROM (
SELECT [Name]
FROM [TableA]
UNION
SELECT TOP 3 [Name]
FROM [TableB]) [T]
FOR JSON PATH),'[]')) AS [Units]
FROM [Contact] [C]
) [Data]
FOR JSON PATH, INCLUDE_NULL_VALUES)
Expected result :
"Units": "[{"Name":"Unit25"}]",
How to achieve ?