I'm executing the following statement:
SELECT
json_query (
(
SELECT * FROM
(
SELECT
NULL AS test1,
NULL AS test2,
NULL AS test3,
NULL AS test4
WHERE
1 = 0
UNION
SELECT
CASE WHEN 1 = 0 THEN NULL ELSE 'abc' END AS test1,
CASE WHEN 1 = 0 THEN NULL ELSE 'xyz' END AS test2,
CASE WHEN 1 = 0 THEN NULL ELSE 'def' END AS test3,
json_query (
CASE WHEN 1 = 0 THEN NULL ELSE (
SELECT 'abc' AS testsub1 ,
( SELECT '487') AS testsub2 FOR json path, without_array_wrapper
) END
) AS test4
) AS test5 FOR json path
)
) AS [test6]
ORDER BY
1 DESC FOR json path
This is the result:
[
{
"test6":[
{
"test1":"abc",
"test2":"xyz",
"test3":"def",
"test4":"{\ "testsub1\ ":\ "abc\ ", \" testsub2 \": \ "487 \ "}"
}
]
}
]
How to avoid the escaping issue in the sub-queries?