Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2022 (16.x)
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL analytics endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
Tests whether a specified SQL/JSON path exists in the input JSON string.
Transact-SQL syntax conventions
JSON_PATH_EXISTS( value_expression , sql_json_path )
A character expression.
A valid SQL/JSON path to test in the input.
Returns an int value of 1
or 0
or NULL
. Returns NULL
if the value_expression or input is a SQL NULL
value. Returns 1
if the given SQL/JSON path exists in the input or returns a non-empty sequence. Returns 0
otherwise.
The JSON_PATH_EXISTS
function doesn't return errors.
The following example returns 1 since the input JSON string contains the specified SQL/JSON path. This example uses a nested path where the key is present in another object.
DECLARE @jsonInfo AS NVARCHAR (MAX);
SET @jsonInfo = N'{"info":{"address":[{"town":"Paris"},{"town":"London"}]}}';
SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.address');
Here's the result set.
1
The following example returns 0 since the input JSON string doesn't contain the specified SQL/JSON path.
DECLARE @jsonInfo AS NVARCHAR (MAX);
SET @jsonInfo = N'{"info":{"address":[{"town":"Paris"},{"town":"London"}]}}';
SELECT JSON_PATH_EXISTS(@jsonInfo, '$.info.addresses');
Here's the result set.
0
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today