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
Saman Gholami
  • 3,416
  • 7
  • 30
  • 71

1 Answers1

20

You just need the WITHOUT_ARRAY_WRAPPER option:

SELECT 1 AS One,2 AS Two,3 AS Three
FOR JSON PATH ,WITHOUT_ARRAY_WRAPPER; 
S.Karras
  • 1,483
  • 15
  • 19