10

I'm using SQL SERVER 2016 JSON result, but I don't know why it converts everything to array, e.g. if I execute the following query it returns an array instead of an object:

SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH

The result is:

[{"One":1,"Two":2,"Three":3}]

But I would like it to return:

{"One":1,"Two":2,"Three":3}

Also I tested this query, but the result was the same, again an array:

SELECT TOP 1 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH

1 Answer 1

21

You just need the WITHOUT_ARRAY_WRAPPER option:

SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH ,WITHOUT_ARRAY_WRAPPER; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.