{"id":14651,"date":"2016-01-08T09:30:00","date_gmt":"2016-01-08T17:30:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/dataplatforminsider\/2016\/01\/08\https://www.microsoft.com/json-in-sql-server-2016-part-4-of-4\/"},"modified":"2024-01-22T22:52:28","modified_gmt":"2024-01-23T06:52:28","slug":"json-in-sql-server-2016-part-4-of-4","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/sql-server\/blog\/2016\/01\/08\https://www.microsoft.com/json-in-sql-server-2016-part-4-of-4\/","title":{"rendered":"JSON in SQL Server 2016: Part 4 of 4"},"content":{"rendered":"

Exporting Data as JSON – FOR JSON<\/h1>\n

In this final post of our four-part JSON series, we showcase the ability to format query results as JSON text using the FOR JSON clause. If you are familiar with the FOR XML clause, you will easily understand FOR JSON.<\/p>\n

\"<\/a><\/p>\n

When you add the FOR JSON clause at the end of a SQL SELECT query, SQL Server will take the results, format them as JSON text, and return them to the client. Every row will be formatted as one JSON object, values in cells of the result set will be generated as values of JSON objects, and column names or aliases will be used as key names. We have two kinds of FOR JSON clauses:<\/p>\n