August 2019
Beginner to intermediate
696 pages
15h 45m
English
By specifying the ROOT option in the FOR JSON query, you can add a single, top-level element to the JSON output. The following code shows this:
SELECT TOP (3) PersonID, FullName, EmailAddress, PhoneNumber
FROM Application.People ORDER BY PersonID ASC FOR JSON AUTO, ROOT('Persons');
Here is the result:
{
"Persons":[
{
"PersonID":1,
"FullName":"Data Conversion Only"
},
{
"PersonID":2,
"FullName":"Kayla Woodcock",
"EmailAddress":"kaylaw@wideworldimporters.com",
"PhoneNumber":"(415) 555-0102"
},
{
"PersonID":3,
"FullName":"Hudson Onslow",
"EmailAddress":"hudsono@wideworldimporters.com",
"PhoneNumber":"(415) 555-0102"
}
]
}
By specifying the root element, you have converted the outer array to a single complex ...
Read now
Unlock full access