All I try to get is a simple SQL statement to build:
{"status":{"code":404,"message":"Not found"},"otherthing":20}
If I set as :
DECLARE @ReturnJSON nvarchar(max)
SET @ReturnJSON = (
SELECT (
SELECT 404 as [code]
,'Not found' as [message]
FOR JSON PATH ) as [status]
, 20 as [otherthing]
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER) ;
SELECT @ReturnJSON
I get the second level under an array wrapper, like this:
{"status":[{"code":404,"message":"Not found"}],"otherthing":20}
But if I add the WITHOUT_ARRAY_WRAPPER
on the second level...
DECLARE @ReturnJSON nvarchar(max)
SET @ReturnJSON = (
SELECT (
SELECT 404 as [code]
,'Not found' as [message]
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER ) as [status]
, 20 as [otherthing]
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER) ;
SELECT @ReturnJSON
something funny happens:
{"status":"{"code":404,"message":"Not found"}","otherthing":20}
I am missing something, I know, sure, but I can not for-see
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…