Formatting Queries As JSON With FOR JSON

Kevin Feasel

2018-08-23

JSON

Eduardo Pivaral shows off the FOR JSON functionality in SQL Server 2016 and later:

For most of real-world applications, the JSON AUTO will not give you the control you could need over your file format, for having more control over it, you must use the JSON PATH option, along with the ROOT option as follows:

SELECT TOP 10 id, dataVarchar, dataNumeric, dataInt, dataDate
FROM [dbo].[MyTestTable]
FOR JSON PATH, ROOT('TestTable')

Eduardo has several examples along these lines.

Related Posts

Searching Complex JSON With SQL Server

Kevin Feasel

2019-02-27

JSON

Bert Wagner gives us a way that you can quickly search through complicated JSON: Computed column indexes make querying JSON data fast and efficient, especially when the schema of the JSON data is the same throughout a table. It’s also possible to break out a well-known complex JSON structure into multiple SQL Server tables. However, what […]

Read More

Azure SQL Managed Instance Inventory Analysis

Kevin Feasel

2018-10-03

Cloud, JSON

Jovan Popovic shows us how to use the Azure CLI plus JSON support in SQL Server to manage a list of Azure SQL Managed Instances: Sometime you would need to know how many Managed Instance you have created in Azure cloud. Although you can find all information about the Azure SQL Managed Instances in Azure […]

Read More

Categories

August 2018
MTWTFSS
« Jul Sep »
 12345
6789101112
13141516171819
20212223242526
2728293031