JSON path exists
Returns true when the supplied JSON path expression matches within the left document.
Category: comparison
SQL symbol: @?
Syntax
sql
<document> @? <path>Parameters
<document>— The JSON document to test. Acceptsnvarchar,varbinary,varchar,variant.<path>— The path to look for. It is resolved to RFC 6901 tokens once, when the query is planned. Acceptsnvarchar,varbinary,varchar. Must be a literal.
Returns
Examples
sql
SELECT '{"contact": {"email": "a@b.c"}}' @? '$.contact.email';true
sql
SELECT '{"a": null}' @? '$.a', '{"a": 1}' @? '$.b';true | false
Signatures
nvarchar @? nvarchar→ booleannvarchar @? varbinary→ booleannvarchar @? varchar→ booleanvarbinary @? nvarchar→ booleanvarbinary @? varbinary→ booleanvarbinary @? varchar→ booleanvarchar @? nvarchar→ booleanvarchar @? varbinary→ booleanvarchar @? varchar→ booleanvariant @? nvarchar→ booleanvariant @? varchar→ boolean
Notes
The path must be a literal — it is resolved to RFC 6901 tokens once when the query is planned, using the same resolver -> uses, so doc @? 'city', doc @? '$.contact.email' and doc @? '/contact/email' all name the same thing. Existence is not extraction: a path whose value is JSON null is TRUE here, while doc->'key' IS NOT NULL is FALSE. A NULL document row is NULL; a row whose bytes are not valid JSON is an error, never a silent false.