@@ -4,7 +4,7 @@ description: JSON_PATH_EXISTS tests whether a specified SQL/JSON path exists in
4
4
author : WilliamDAssafMSFT
5
5
ms.author : wiassaf
6
6
ms.reviewer : randolphwest, umajay, jovanpop
7
- ms.date : 01/07 /2025
7
+ ms.date : 04/30 /2025
8
8
ms.service : sql
9
9
ms.subservice : t-sql
10
10
ms.topic : reference
@@ -83,6 +83,61 @@ SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.addresses');
83
83
0
84
84
```
85
85
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
+
86
141
## Related content
87
142
88
143
- [ JSON data in SQL Server] ( ../../relational-databases/json/json-data-sql-server.md )
0 commit comments