Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
When you specify FOR JSON RAW in a query, each row is returned as a flattened JSON representation.
FOR JSON RAW
This clause is the recommended method for retrieving query results as JSON objects as it is the easiest method to parse and understand.
The following query uses FOR JSON RAW to return employee information from the Employees table:
SELECT emp.EmployeeID, so.CustomerID, so.Region FROM Employees AS emp KEY JOIN SalesOrders AS so WHERE emp.EmployeeID <= 195 ORDER BY 1 FOR JSON RAW;
Unlike the results returned if using FOR JSON AUTO, which would hierarchically nest the results, using FOR JSON RAW returns a flattened result set:
[ { "EmployeeID" : 129, "CustomerID" : 107, "Region" : "Eastern" }, { "EmployeeID" : 129, "CustomerID" : 119, "Region" : "Western" }, ... { "EmployeeID" : 129, "CustomerID" : 131, "Region" : "Eastern" }, { "EmployeeID" " 195, "CustomerID" : 176, "Region" : "Eastern" } ]