Learn all about Azure SQL Database both Platform as a Service (PaaS) and Infrastructure as a Service (IaaS). Check our online course “Introduction to Azure SQL Database” (lifetime access).
Examples of Built-In JSON Support in SQL Server and Azure SQL Database
Below we are going to see some examples of utilizing SQL Server’s JSON support.
For the purposes of these demos, I have created a sample tabled called “Students” and I have populated it with random data. Let’s take a look at the first 10 rows of this table:
Example 1: The “FOR JSON AUTO” Clause
In order to extract data from a table and represent it in the JSON format you must use wither the “FOR JSON AUTO” clause or the “FOR JSON PATH” clause.
The “FOR JSON AUTO” clause allows you to have full control over the format of the JSON output. For example, you can specify the root.
Example 2: The “FOR JSON PATH” clause
The “FOR JSON PATH” clause automatically formats the JSON output based on the structure of the source table.
Example 3: The OPENJSON rowset function
Now, if you want to transform JSON data into a tabular form, you can use the OPENJSON rowset function.
Learn more about Azure SQL Database and get started fast and easy! Through our online course, you will get lifetime access to a comprehensive set of lectures and live demonstrations that will get you started with Azure SQL Database in no time! The course is regularly updated with additional educational material!Enroll Now with Discount!
- MSDN Library Article: What’s New in SQL Server 2016, November Update
- MSDN Library Article: Format Query Results as JSON with FOR JSON (SQL Server)
- MSDN Library Article: Convert JSON Data to Rows and Columns with OPENJSON (SQL Server)
- SQL Server 2016 Top Features
- SQL Server 2016 SP1: Breakthrough Changes
- Temporal Tables in SQL Server and Azure SQL Database
- SQL Server 2016: Built-In JSON Support
- Azure Cosmos DB: Learn by Example
- Learn Azure SQL Database: Creating your First Database
- How to Create an Azure SQL Server Virtual Machine
- How to Backup a SQL Server Database from On-Premises to Azure Storage
- What is Azure Advisor?
- … all our Azure-related articles
Check our latest software releases!
Easily generate SQL code snippets with Snippets Generator!
Convert static T-SQL to dynamic and vice versa with Dynamic SQL Generator.
Secure your SQL Server instances with DBA Security Advisor.
Benchmark SQL Server memory-optimized tables with In-Memory OLTP Simulator.
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)