Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit f4fc599

Browse files
authored
Merge pull request #33407 from WilliamDAssafMSFT/20250306-json-fabric
20250306 json fabric
2 parents 74324f2 + 3f1e5e2 commit f4fc599

15 files changed

Lines changed: 519 additions & 499 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: WilliamDAssafMSFT
3+
ms.author: wiassaf
4+
ms.date: 03/06/2025
5+
ms.service: sql
6+
ms.topic: include
7+
---
8+
9+
[!INCLUDE [Applies to](../../includes/applies-md.md)] [!INCLUDE [SQL Server 2016](_ss2016.md)] and later versions [!INCLUDE [Azure SQL Database](_asdb.md)] [!INCLUDE [Azure SQL Managed Instance](_asmi.md)] [!INCLUDE [Azure Synapse Analytics (serverless SQL pool only)](_asa-svrless-sqlpool-only.md)] [!INCLUDE [Fabric SQL analytics endpoint](_fabric-se.md)] [!INCLUDE [Fabric Data Warehouse](_fabric-dw.md)]

docs/relational-databases/json/add-a-root-node-to-json-output-with-the-root-option-sql-server.md

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,67 @@
11
---
22
title: "Add a Root Node to JSON Output with the ROOT Option"
3-
description: "Add a Root Node to JSON Output with the ROOT Option (SQL Server)"
3+
description: "To add a single, top-level element to the JSON output of the FOR JSON clause, specify the ROOT option."
44
author: jovanpop-msft
55
ms.author: jovanpop
66
ms.reviewer: jroth
7-
ms.date: 06/03/2020
7+
ms.date: 03/06/2025
88
ms.service: sql
99
ms.topic: how-to
1010
helpviewer_keywords:
1111
- "ROOT (FOR JSON)"
12-
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
12+
monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric"
1313
---
14-
# Add a Root Node to JSON Output with the ROOT Option (SQL Server)
15-
16-
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-serverless-pool-only](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-serverless-pool-only.md)]
17-
18-
To add a single, top-level element to the JSON output of the **FOR JSON** clause, specify the **ROOT** option.
19-
20-
If you don't specify the **ROOT** option, the JSON output doesn't include a root element.
21-
22-
## Examples
23-
The following table shows the output of the **FOR JSON** clause with and without the **ROOT** option.
24-
25-
The examples in the following table assume that the optional *RootName* argument is empty. If you provide a name for the root element, this value replaces the value **root** in the examples.
26-
27-
Without the **ROOT** option
28-
29-
```json
14+
# Add a Root Node to JSON Output with the ROOT Option
15+
16+
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-serverless-pool-only-fabricse-fabricdw](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-serverless-pool-only-fabricse-fabricdw.md)]
17+
18+
To add a single, top-level element to the JSON output of the `FOR JSON` clause, specify the `ROOT` option.
19+
20+
If you don't specify the `ROOT` option, the JSON output doesn't include a root element.
21+
22+
## Examples
23+
24+
The following table shows the output of the `FOR JSON` clause with and without the `ROOT` option.
25+
26+
The examples in the following table assume that the optional *RootName* argument is empty. If you provide a name for the root element, this value replaces the value `root` in the examples.
27+
28+
**Without the `ROOT` option:**
29+
30+
```json
3031
{
3132
<<json properties>>
3233
}
3334
```
34-
35-
```json
35+
36+
```json
3637
[
3738
<<json array elements>>
3839
]
3940
```
40-
41-
With the **ROOT** option
42-
43-
```json
41+
42+
**With the `ROOT` option:**
43+
44+
```json
4445
{
4546
"root": {
4647
<<json properties>>
4748
}
4849
}
4950
```
50-
51-
```json
51+
52+
```json
5253
{
5354
"root": [
5455
<< json array elements >>
5556
]
5657
}
5758
```
58-
59-
Here's another example of a **FOR JSON** clause with the **ROOT** option. This example specifies a value for the optional *RootName* argument.
60-
59+
60+
Here's another example of a `FOR JSON` clause with the `ROOT` option. This example specifies a value for the optional `RootName` argument.
61+
6162
**Query**
62-
63-
```sql
63+
64+
```sql
6465
SELECT TOP 5
6566
BusinessEntityID As Id,
6667
FirstName, LastName,
@@ -69,10 +70,10 @@ SELECT TOP 5
6970
FROM Person.Person
7071
FOR JSON PATH, ROOT('info')
7172
```
72-
73+
7374
**Result**
74-
75-
```json
75+
76+
```json
7677
{
7778
"info": [{
7879
"Id": 1,
@@ -107,10 +108,10 @@ SELECT TOP 5
107108
}]
108109
}
109110
```
110-
111+
111112
**Result (without root)**
112-
113-
```json
113+
114+
```json
114115
[{
115116
"Id": 1,
116117
"FirstName": "Ken",
@@ -144,18 +145,12 @@ SELECT TOP 5
144145
}]
145146
```
146147

147-
## Learn more about JSON in SQL Server and Azure SQL Database
148-
149-
### Microsoft videos
150-
151-
> [!NOTE]
152-
> 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.
148+
## Learn more about JSON in the SQL Database Engine
153149

154-
For a visual introduction to the built-in JSON support in SQL Server and Azure SQL Database, see the following videos:
150+
For a visual introduction to the built-in JSON support, see the following videos:
155151

156152
- [JSON as a bridge between NoSQL and relational worlds](https://channel9.msdn.com/events/DataDriven-SQLServer2016/JSON-as-bridge-betwen-NoSQL-relational-worlds)
157-
158-
## See Also
159-
[FOR Clause &#40;Transact-SQL&#41;](../../t-sql/queries/select-for-clause-transact-sql.md)
160-
161-
153+
154+
## Related content
155+
156+
- [FOR Clause (Transact-SQL)](../../t-sql/queries/select-for-clause-transact-sql.md)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
title: "Parse and transform JSON data with OPENJSON"
2+
title: "Parse and Transform JSON Data with OPENJSON"
33
description: OPENJSON converts JSON into a set of rows and columns. Use it to run any SQL query on the returned data, or insert it into a SQL Server table.
44
author: jovanpop-msft
55
ms.author: jovanpop
66
ms.reviewer: jroth, randolphwest
7-
ms.date: 05/06/2024
7+
ms.date: 03/06/2025
88
ms.service: sql
99
ms.topic: how-to
1010
helpviewer_keywords:
1111
- "OPENJSON"
1212
- "JSON, importing"
1313
- "importing JSON"
14-
monikerRange: "=azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current"
14+
monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric"
1515
---
1616
# Parse and transform JSON data with OPENJSON
1717

18-
[!INCLUDE [SQL Server ASDB, ASDBMI, ASDW](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa.md)]
18+
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-serverless-pool-only-fabricse-fabricdw](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-serverless-pool-only-fabricse-fabricdw.md)]
1919

2020
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. For more information about working with JSON data in the [!INCLUDE [ssdenoversion-md](../../includes/ssdenoversion-md.md)], see [JSON data in SQL Server](json-data-sql-server.md).
2121

docs/relational-databases/json/format-json-output-automatically-with-auto-mode-sql-server.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
---
22
title: "Format JSON Output Automatically with AUTO Mode"
3-
description: "Format JSON Output Automatically with AUTO Mode (SQL Server)"
3+
description: "To format the output of the FOR JSON clause automatically based on the structure of the SELECT statement, specify the AUTO option."
44
author: jovanpop-msft
55
ms.author: jovanpop
66
ms.reviewer: jroth
7-
ms.date: 06/03/2020
7+
ms.date: 03/06/2025
88
ms.service: sql
99
ms.topic: how-to
1010
helpviewer_keywords:
1111
- "FOR JSON AUTO"
12-
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
12+
monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric"
1313
---
14-
# Format JSON Output Automatically with AUTO Mode (SQL Server)
15-
16-
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-serverless-pool-only](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-serverless-pool-only.md)]
17-
18-
To format the output of the **FOR JSON** clause automatically based on the structure of the **SELECT** statement, specify the **AUTO** option.
19-
20-
When you specify the **AUTO** option, the format of the JSON output is automatically determined based on the order of columns in the SELECT list and their source tables. You can't change this format.
21-
22-
The alternative is to use the **PATH** option to maintain control over the output.
23-
- For more info about the **PATH** option, see [Format Nested JSON Output with PATH Mode](../../relational-databases/json/format-nested-json-output-with-path-mode-sql-server.md).
24-
- For an overview of both options, see [Format Query Results as JSON with FOR JSON](../../relational-databases/json/format-query-results-as-json-with-for-json-sql-server.md).
25-
26-
A query that uses the **FOR JSON AUTO** option must have a **FROM** clause.
27-
28-
Here are some examples of the **FOR JSON** clause with the **AUTO** option. [Azure Data Studio](/azure-data-studio/download-azure-data-studio) is the recommended query editor for JSON queries because it auto-formats the JSON results (as seen in this article) instead of displaying a flat string.
29-
14+
# Format JSON Output Automatically with AUTO Mode
15+
16+
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-serverless-pool-only-fabricse-fabricdw](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-serverless-pool-only-fabricse-fabricdw.md)]
17+
18+
To format the output of the `FOR JSON` clause automatically based on the structure of the `SELECT` statement, specify the `AUTO` option.
19+
20+
When you specify the `AUTO` option, the format of the JSON output is automatically determined based on the order of columns in the SELECT list and their source tables. You can't change this format.
21+
22+
The alternative is to use the `PATH` option to maintain control over the output.
23+
- For more info about the `PATH` option, see [Format Nested JSON Output with PATH Mode](format-nested-json-output-with-path-mode-sql-server.md).
24+
- For an overview of both options, see [Format query results as JSON with FOR JSON](format-query-results-as-json-with-for-json-sql-server.md).
25+
26+
A query that uses the `FOR JSON AUTO` option must have a `FROM` clause.
27+
28+
Here are some examples of the `FOR JSON` clause with the `AUTO` option. [Azure Data Studio](/azure-data-studio/download-azure-data-studio) is the recommended query editor for JSON queries because it auto-formats the JSON results (as seen in this article) instead of displaying a flat string.
29+
3030
## Examples
3131

3232
### Example 1
33+
3334
**Query**
34-
35-
When a query references only one table, the results of the FOR JSON AUTO clause are similar to the results of FOR JSON PATH . In this case, FOR JSON AUTO doesn't create nested objects. The only difference is that FOR JSON AUTO outputs dot-separated aliases (for example, `Info.MiddleName` in the following example) as keys with dots, not as nested objects.
36-
37-
```sql
35+
36+
When a query references only one table, the results of the `FOR JSON AUTO` clause are similar to the results of `FOR JSON PATH`. In this case, `FOR JSON AUTO` doesn't create nested objects. The only difference is that `FOR JSON AUTO` outputs dot-separated aliases (for example, `Info.MiddleName` in the following example) as keys with dots, not as nested objects.
37+
38+
```sql
3839
SELECT TOP 5
3940
BusinessEntityID As Id,
4041
FirstName, LastName,
@@ -43,10 +44,10 @@ SELECT TOP 5
4344
FROM Person.Person
4445
FOR JSON AUTO
4546
```
46-
47+
4748
**Result**
48-
49-
```json
49+
50+
```json
5051
[{
5152
"Id": 1,
5253
"FirstName": "Ken",
@@ -77,10 +78,10 @@ SELECT TOP 5
7778
### Example 2
7879

7980
**Query**
80-
81+
8182
When you join tables, columns in the first table are generated as properties of the root object. Columns in the second table are generated as properties of a nested object. The table name or alias of the second table (for example, `D` in the following example) is used as the name of the nested array.
82-
83-
```sql
83+
84+
```sql
8485
SELECT TOP 2 SalesOrderNumber,
8586
OrderDate,
8687
UnitPrice,
@@ -90,10 +91,10 @@ FROM Sales.SalesOrderHeader H
9091
ON H.SalesOrderID = D.SalesOrderID
9192
FOR JSON AUTO
9293
```
93-
94+
9495
**Result**
95-
96-
```json
96+
97+
```json
9798
[{
9899
"SalesOrderNumber": "SO43659",
99100
"OrderDate": "2011-05-31T00:00:00",
@@ -113,11 +114,11 @@ FOR JSON AUTO
113114
```
114115

115116
### Example 3
116-
117+
117118
**Query**
118119
Instead of using FOR JSON AUTO, you can nest a FOR JSON PATH subquery in the SELECT statement, as shown in the following example. This example outputs the same result as the preceding example.
119-
120-
```sql
120+
121+
```sql
121122
SELECT TOP 2
122123
SalesOrderNumber,
123124
OrderDate,
@@ -128,10 +129,10 @@ SELECT TOP 2
128129
FROM Sales.SalesOrderHeader AS H
129130
FOR JSON PATH
130131
```
131-
132+
132133
**Result**
133-
134-
```json
134+
135+
```json
135136
[{
136137
"SalesOrderNumber": "SO43659",
137138
"OrderDate": "2011-05-31T00:00:00",
@@ -147,13 +148,12 @@ FOR JSON PATH
147148
}]
148149
```
149150

150-
## Learn more about JSON in SQL Server and Azure SQL Database
151-
152-
### Microsoft videos
151+
## Learn more about JSON in the SQL Database Engine
153152

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

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

158-
## See Also
159-
[FOR Clause &#40;Transact-SQL&#41;](../../t-sql/queries/select-for-clause-transact-sql.md)
157+
## Related content
158+
159+
- [FOR Clause (Transact-SQL)](../../t-sql/queries/select-for-clause-transact-sql.md)

0 commit comments

Comments
 (0)