Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2016 (13.x) and later
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics (serverless SQL pool only)
To remove the square brackets that surround the JSON output of the FOR JSON clause by default, specify the WITHOUT_ARRAY_WRAPPER option. Use this option with a single-row result to generate a single JSON object as output instead of an array with a single element.
If you use this option with a multiple-row result, the resulting output is not valid JSON because of the multiple elements and the missing square brackets.
The following example shows the output of the FOR JSON clause with and without the WITHOUT_ARRAY_WRAPPER option.
Query
SELECT 2015 as year, 12 as month, 15 as day
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
Result with the WITHOUT_ARRAY_WRAPPER option
{
"year": 2015,
"month": 12,
"day": 15
}
Result (default) without the WITHOUT_ARRAY_WRAPPER option
[{
"year": 2015,
"month": 12,
"day": 15
}]
Here's another example of a FOR JSON clause with and without the WITHOUT_ARRAY_WRAPPER option. This example produces a multiple-row result. The output is not valid JSON because of the multiple elements and the missing square brackets.
Query
SELECT TOP 3 SalesOrderNumber, OrderDate, Status
FROM Sales.SalesOrderHeader
ORDER BY ModifiedDate
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
Result with the WITHOUT_ARRAY_WRAPPER option
{
"SalesOrderNumber": "SO43662",
"OrderDate": "2011-05-31T00:00:00",
"Status": 5
}, {
"SalesOrderNumber": "SO43661",
"OrderDate": "2011-05-31T00:00:00",
"Status": 5
}, {
"SalesOrderNumber": "SO43660",
"OrderDate": "2011-05-31T00:00:00",
"Status": 5
}
Result (default) without the WITHOUT_ARRAY_WRAPPER option
[{
"SalesOrderNumber": "SO43662",
"OrderDate": "2011-05-31T00:00:00",
"Status": 5
}, {
"SalesOrderNumber": "SO43661",
"OrderDate": "2011-05-31T00:00:00",
"Status": 5
}, {
"SalesOrderNumber": "SO43660",
"OrderDate": "2011-05-31T00:00:00",
"Status": 5
}]
Note
Some of the video links in this section may not work at this time. Microsoft is migrating content formerly on Channel 9 to a new platform. We will update the links as the videos are migrated to the new platform.
For a visual introduction to the built-in JSON support in SQL Server and Azure SQL Database, see the following videos:
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Understand data warehouse developer features of Azure Synapse Analytics - Training
Understand data warehouse developer features of Azure Synapse Analytics
Documentation
Format JSON Output Automatically with AUTO Mode - SQL Server
Format JSON Output Automatically with AUTO Mode (SQL Server)
Format Nested JSON Output with PATH Mode - SQL Server
Format Nested JSON Output with PATH Mode (SQL Server)
Add a Root Node to JSON Output with the ROOT Option - SQL Server
Add a Root Node to JSON Output with the ROOT Option (SQL Server)