SQL Server › JSON Support in SQL Server
How do you generate JSON formatted output directly from a SQL query's result set?
IntermediateAnswer
You add the FOR JSON clause to the end of your SELECT statement, choosing either AUTO to let SQL Server automatically structure the output based on your table and column names, or PATH for more explicit control over the exact shape and nesting of the resulting JSON document.
SELECT OrderId, CustomerName, Amount
FROM Orders
FOR JSON PATH;Real-world example A web API endpoint queries order data directly from SQL Server using FOR JSON PATH, returning properly formatted JSON that can be sent straight to a front end application without any additional conversion step in the application code.