Skip to content

Commit e554cf9

Browse files
20250430 JSON wildcard sample to JSON_PATH_EXISTS (#33977)
1 parent 719be42 commit e554cf9

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: JSON_PATH_EXISTS tests whether a specified SQL/JSON path exists in
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
66
ms.reviewer: randolphwest, umajay, jovanpop
7-
ms.date: 01/07/2025
7+
ms.date: 04/30/2025
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: reference
@@ -83,6 +83,61 @@ SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.addresses');
8383
0
8484
```
8585

86+
### Example 3
87+
88+
The following example uses `JSON_PATH_EXISTS()` with a wildcard:
89+
90+
```sql
91+
DECLARE @jsonInfo AS NVARCHAR (MAX);
92+
93+
94+
95+
SET @jsonInfo = N'{"info":{"address":[{"town":"Paris"},{"town":"London"}]}}';
96+
97+
98+
99+
SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.address[*].town'); -- Returns: 1
100+
```
101+
102+
[!INCLUDE [ssresult-md](../../includes/ssresult-md.md)]
103+
104+
```output
105+
1
106+
```
107+
108+
The following looks for at least one element in array has an object with key `town`, and finds one.
109+
110+
```sql
111+
SET @jsonInfo = N'{"info":{"address":[{"town":"Paris"},{"city":"London"}]}}';
112+
113+
114+
115+
SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.address[*].town'); -- Returns: 1 (at least one element in array has an object with key "town")
116+
```
117+
118+
[!INCLUDE [ssresult-md](../../includes/ssresult-md.md)]
119+
120+
```output
121+
1
122+
```
123+
124+
The following looks for at least one element in array has an object with key `town`, but finds none.
125+
126+
```sql
127+
SET @jsonInfo = N'{"info":{"address":[{"city":"Paris"},{"city":"London"}]}}';
128+
129+
130+
131+
SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.address[*].town'); -- Returns: 0 (no elements in array has an object with key "town")
132+
```
133+
134+
[!INCLUDE [ssresult-md](../../includes/ssresult-md.md)]
135+
136+
```output
137+
0
138+
```
139+
140+
86141
## Related content
87142

88143
- [JSON data in SQL Server](../../relational-databases/json/json-data-sql-server.md)

0 commit comments

Comments
 (0)