Skip to content

Commit 3679764

Browse files
authored
Merge pull request #10096 from julieMSFT/JSON
Updating JSON articles to show supported in SQL DW
2 parents b6c67b0 + 94e1ae1 commit 3679764

8 files changed

Lines changed: 145 additions & 108 deletions

docs/relational-databases/json/convert-json-data-to-rows-and-columns-with-openjson-sql-server.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ author: jovanpop-msft
1515
ms.author: jovanpop
1616
ms.reviewer: genemi
1717
manager: craigg
18-
monikerRange: "=azuresqldb-current||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current"
18+
monikerRange: "=azuresqldb-current||= azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current"
1919
---
2020
# Parse and Transform JSON Data with OPENJSON (SQL Server)
21-
[!INCLUDE[appliesto-ss-asdb-xxxx-xxx-md](../../includes/appliesto-ss-asdb-xxxx-xxx-md.md)]
21+
[!INCLUDE[appliesto-ss-asdb-asdw-xxx-md](../../includes/appliesto-ss-asdb-asdw-xxx-md.md)]
2222

2323
The **OPENJSON** rowset function converts JSON text into a set of rows and columns. After you transform a JSON collection into a rowset with **OPENJSON**, you can run any SQL query on the returned data or insert it into a SQL Server table.
2424

@@ -37,9 +37,10 @@ When you use the **OPENJSON** function without providing an explicit schema for
3737
**OPENJSON** returns each property of the JSON object, or each element of the array, as a separate row.
3838

3939
Here's a quick example that uses **OPENJSON** with the default schema - that is, without the optional **WITH** clause - and returns one row for each property of the JSON object.
40-
40+
4141
**Example**
42-
```sql
42+
43+
```sql
4344
DECLARE @json NVARCHAR(MAX)
4445

4546
SET @json='{"name":"John","surname":"Doe","age":45,"skills":["SQL","C#","MVC"]}';
@@ -48,7 +49,7 @@ SELECT *
4849
FROM OPENJSON(@json);
4950
```
5051

51-
**Results**
52+
**Results**
5253

5354
|key|value|type|
5455
|---------|-----------|----------|
@@ -63,8 +64,8 @@ For more info and examples, see [Use OPENJSON with the Default Schema (SQL S
6364

6465
For syntax and usage, see [OPENJSON (Transact-SQL)](../../t-sql/functions/openjson-transact-sql.md).
6566

66-
6767
## Option 2 - OPENJSON output with an explicit structure
68+
6869
When you specify a schema for the results by using the **WITH** clause of the **OPENJSON** function, the function returns a table with only the columns that you define in the **WITH** clause. In the optional **WITH** clause, you specify a set of output columns, their types, and the paths of the JSON source properties for each output value. **OPENJSON** iterates through the array of JSON objects, reads the value on the specified path for each column, and converts the value to the specified type.
6970

7071
Here's a quick example that uses **OPENJSON** with a schema for the output that you explicitly specify in the **WITH** clause.
@@ -109,7 +110,7 @@ WITH (
109110
)
110111
```
111112

112-
**Results**
113+
**Results**
113114

114115
|Number|Date|Customer|Quantity|
115116
|------------|----------|--------------|--------------|
@@ -123,11 +124,13 @@ This function returns and formats the elements of a JSON array.
123124
- For each column, specified by using the `colName type json_path` syntax, **OPENJSON** converts the value found in each array element on the specified path to the specified type. In this example, values for the `Date` column are taken from each element on the path `$.Order.Date` and converted to datetime values.
124125

125126
### More info about OPENJSON with an explicit schema
127+
126128
For more info and examples, see [Use OPENJSON with an Explicit Schema (SQL Server)](../../relational-databases/json/use-openjson-with-an-explicit-schema-sql-server.md).
127129

128130
For syntax and usage, see [OPENJSON (Transact-SQL)](../../t-sql/functions/openjson-transact-sql.md).
129131

130132
## OPENJSON requires Compatibility Level 130
133+
131134
The **OPENJSON** function is available only under **compatibility level 130**. If your database compatibility level is lower than 130, SQL Server can't find and run the **OPENJSON** function. Other built-in JSON functions are available at all compatibility levels.
132135

133136
You can check compatibility level in the `sys.databases` view or in database properties.
@@ -141,13 +144,12 @@ You can change the compatibility level of a database by using the following comm
141144

142145
For a visual introduction to the built-in JSON support in SQL Server and Azure SQL Database, see the following videos:
143146

144-
- [SQL Server 2016 and JSON Support](https://channel9.msdn.com/Shows/Data-Exposed/SQL-Server-2016-and-JSON-Support)
147+
- [SQL Server 2016 and JSON Support](https://channel9.msdn.com/Shows/Data-Exposed/SQL-Server-2016-and-JSON-Support)
145148

146-
- [Using JSON in SQL Server 2016 and Azure SQL Database](https://channel9.msdn.com/Shows/Data-Exposed/Using-JSON-in-SQL-Server-2016-and-Azure-SQL-Database)
149+
- [Using JSON in SQL Server 2016 and Azure SQL Database](https://channel9.msdn.com/Shows/Data-Exposed/Using-JSON-in-SQL-Server-2016-and-Azure-SQL-Database)
147150

148-
- [JSON as a bridge between NoSQL and relational worlds](https://channel9.msdn.com/events/DataDriven/SQLServer2016/JSON-as-a-bridge-betwen-NoSQL-and-relational-worlds)
151+
- [JSON as a bridge between NoSQL and relational worlds](https://channel9.msdn.com/events/DataDriven/SQLServer2016/JSON-as-a-bridge-betwen-NoSQL-and-relational-worlds)
149152

150153
## See Also
151154
[OPENJSON (Transact-SQL)](../../t-sql/functions/openjson-transact-sql.md)
152-
153-
155+

docs/relational-databases/json/json-data-sql-server.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ author: jovanpop-msft
1414
ms.author: jovanpop
1515
ms.reviewer: genemi
1616
manager: craigg
17-
monikerRange: "=azuresqldb-current||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current"
17+
monikerRange: "=azuresqldb-current||= azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current"
1818
---
1919

2020
# JSON data in SQL Server
21-
[!INCLUDE[appliesto-ss2016-asdb-xxxx-xxx-md.md](../../includes/tsql-appliesto-ss2016-asdb-xxxx-xxx-md.md)]
21+
[!INCLUDE[appliesto-ss2016-asdb-asdw-xxx-md.md](../../includes/tsql-appliesto-ss2016-asdb-asdw-xxx-md.md)]
2222

2323
JSON is a popular textual data format that's used for exchanging data in modern web and mobile applications. JSON is also used for storing unstructured data in log files or NoSQL databases such as Microsoft Azure Cosmos DB. Many REST web services return results that are formatted as JSON text or accept data that's formatted as JSON. For example, most Azure services, such as Azure Search, Azure Storage, and Azure Cosmos DB, have REST endpoints that return or consume JSON. JSON is also the main format for exchanging data between webpages and web servers by using AJAX calls.
2424

2525
JSON functions in SQL Server enable you to combine NoSQL and relational concepts in the same database. Now you can combine classic relational columns with columns that contain documents formatted as JSON text in the same table, parse and import JSON documents in relational structures, or format relational data to JSON text. You see how JSON functions connect relational and NoSQL concepts in SQL Server and Azure SQL Database in the following video:
2626

2727
*JSON as a bridge between NoSQL and relational worlds*
2828
> [!VIDEO https://channel9.msdn.com/events/DataDriven/SQLServer2016/JSON-as-a-bridge-betwen-NoSQL-and-relational-worlds/player]
29-
30-
Here's an example of JSON text:
31-
32-
```json
29+
30+
Here's an example of JSON text:
31+
32+
```json
3333
[{
3434
"name": "John",
3535
"skills": ["SQL", "C#", "Azure"]
3636
}, {
3737
"name": "Jane",
3838
"surname": "Doe"
3939
}]
40-
```
40+
```
4141

4242
By using SQL Server built-in functions and operators, you can do the following things with JSON text:
4343

@@ -121,7 +121,7 @@ FROM OPENJSON(@json)
121121

122122
**Results**
123123

124-
|id|firstName|lastName|age|dateOfBirth|
124+
|ID|firstName|lastName|age|dateOfBirth|
125125
|--------|---------------|--------------|---------|-----------------|
126126
|2|John|Smith|25||
127127
|5|Jane|Smith||2005-11-04T12:00:00|
@@ -150,7 +150,7 @@ N'[
150150

151151
SELECT *
152152
FROM OPENJSON(@json)
153-
WITH (id int 'strict $.id',
153+
WITH id int 'strict $.id',
154154
firstName nvarchar(50) '$.info.name', lastName nvarchar(50) '$.info.surname',
155155
age int, dateOfBirth datetime2 '$.dob',
156156
skills nvarchar(max) '$.info.skills' as json)
@@ -162,7 +162,7 @@ The result of this query is shown in the following table:
162162

163163
**Results**
164164

165-
|id|firstName|lastName|age|dateOfBirth|skill|
165+
|ID|firstName|lastName|age|dateOfBirth|skill|
166166
|--------|---------------|--------------|---------|-----------------|----------|
167167
|2|John|Smith|25|||
168168
|5|Jane|Smith||2005-11-04T12:00:00|SQL|
@@ -172,6 +172,10 @@ The result of this query is shown in the following table:
172172
`OUTER APPLY OPENJSON` will join first level entity with sub-array and return flatten resultset. Due to JOIN, the second row will be repeated for every skill.
173173

174174
### Convert SQL Server data to JSON or export JSON
175+
176+
>[!NOTE]
177+
>Converting Azure SQL Data Warehouse data to JSON or exporting JSON is not supported.
178+
175179
Format SQL Server data or the results of SQL queries as JSON by adding the **FOR JSON** clause to a **SELECT** statement. Use **FOR JSON** to delegate the formatting of JSON output from your client applications to SQL Server. For more information, see [Format Query Results as JSON with FOR JSON (SQL Server)](../../relational-databases/json/format-query-results-as-json-with-for-json-sql-server.md).
176180

177181
The following example uses PATH mode with the **FOR JSON** clause:
@@ -327,11 +331,11 @@ If you have a web service that takes data from the database layer and returns it
327331

328332
For example, you might want to generate JSON output that's compliant with the OData specification. The web service expects a request and response in the following format:
329333

330-
- Request: `/Northwind/Northwind.svc/Products(1)?$select=ProductID,ProductName`
334+
- Request: `/Northwind/Northwind.svc/Products(1)?$select=ProductID,ProductName`
331335

332-
- Response: `{"@odata.context":"https://services.odata.org/V4/Northwind/Northwind.svc/$metadata#Products(ProductID,ProductName)/$entity","ProductID":1,"ProductName":"Chai"}`
336+
- Response: `{"@odata.context":"https://services.odata.org/V4/Northwind/Northwind.svc/$metadata#Products(ProductID,ProductName)/$entity","ProductID":1,"ProductName":"Chai"}`
333337

334-
This OData URL represents a request for the ProductID and ProductName columns for the product with `id` 1. You can use **FOR JSON** to format the output as expected in SQL Server.
338+
This OData URL represents a request for the ProductID and ProductName columns for the product with `ID` 1. You can use **FOR JSON** to format the output as expected in SQL Server.
335339

336340
```sql
337341
SELECT 'https://services.odata.org/V4/Northwind/Northwind.svc/$metadata#Products(ProductID,ProductName)/$entity'

docs/t-sql/functions/isjson-transact-sql.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ author: "jovanpop-msft"
1818
ms.author: "jovanpop"
1919
ms.reviewer: genemi
2020
manager: craigg
21+
monikerRange: "= azuresqldb-current||= azure-sqldw-latest||>= sql-server-2016||>= sql-server-linux-2017||= sqlallproducts-allversions"
2122
---
2223
# ISJSON (Transact-SQL)
23-
[!INCLUDE[tsql-appliesto-ss2016-asdb-xxxx-xxx-md](../../includes/tsql-appliesto-ss2016-asdb-xxxx-xxx-md.md)]
24+
[!INCLUDE[tsql-appliesto-ss2016-asdb-asdw-xxx-md](../../includes/tsql-appliesto-ss2016-asdb-asdw-xxx-md.md)]
2425

2526
Tests whether a string contains valid JSON.
2627

docs/t-sql/functions/json-functions-transact-sql.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ author: "jovanpop-msft"
1414
ms.author: "jovanpop"
1515
ms.reviewer: genemi
1616
manager: craigg
17+
monikerRange: "= azuresqldb-current||= azure-sqldw-latest||>= sql-server-2016||>= sql-server-linux-2017||= sqlallproducts-allversions"
1718
---
1819
# JSON Functions (Transact-SQL)
19-
[!INCLUDE[tsql-appliesto-ss2016-asdb-xxxx-xxx-md](../../includes/tsql-appliesto-ss2016-asdb-xxxx-xxx-md.md)]
20+
21+
[!INCLUDE[tsql-appliesto-ss2016-asdb-asdw-xxx-md](../../includes/tsql-appliesto-ss2016-asdb-asdw-xxx-md.md)]
2022

2123
Use the functions described on the pages in this section to validate or change JSON text or to extract simple or complex values.
2224

@@ -28,10 +30,9 @@ Use the functions described on the pages in this section to validate or change J
2830
|[JSON_MODIFY](../../t-sql/functions/json-modify-transact-sql.md)|Updates the value of a property in a JSON string and returns the updated JSON string.|
2931

3032
For more info about the built-in support for JSON in [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], see [JSON Data (SQL Server)](../../relational-databases/json/json-data-sql-server.md).
31-
32-
## See Also
33-
[Validate, Query, and Change JSON Data with Built-in Functions (SQL Server)](../../relational-databases/json/validate-query-and-change-json-data-with-built-in-functions-sql-server.md)
34-
[JSON Path Expressions (SQL Server)](../../relational-databases/json/json-path-expressions-sql-server.md)
35-
[JSON Data (SQL Server)](../../relational-databases/json/json-data-sql-server.md)
36-
37-
33+
34+
## See Also
35+
36+
- [Validate, Query, and Change JSON Data with Built-in Functions (SQL Server)](../../relational-databases/json/validate-query-and-change-json-data-with-built-in-functions-sql-server.md)
37+
- [JSON Path Expressions (SQL Server)](../../relational-databases/json/json-path-expressions-sql-server.md)
38+
- [JSON Data (SQL Server)](../../relational-databases/json/json-data-sql-server.md)

0 commit comments

Comments
 (0)