JSON_PATH_EXISTS Function
JSON_PATH_EXISTS() Function
Last updated:
Warning: Review and test in a non-production environment before running.
-- Examples from Microsoft Learn: JSON_PATH_EXISTS (Transact-SQL) – https://learn.microsoft.com/en-us/sql/t-sql/functions/json-path-exists-transact-sql
JSON_PATH_EXISTS
SQL Server 2022 (16.x) Preview
Tests whether a specified SQL/JSON path exists in the input JSON string.
JSON_PATH_EXISTS( value_expression, sql_json_path )
examples:
The following example returns 1 since the input JSON string contains the specified SQL/JSON path.
DECLARE @jsonInfo NVARCHAR(MAX)
SET @jsonInfo=N'{"info":{"address":[{"town":"Paris"},{"town":"London"}]}}';
SELECT JSON_PATH_EXISTS(@jsonInfo,'$.info.address'); -- 1
The following example returns 0 since the input JSON string contains the specified SQL/JSON path.
DECLARE @jsonInfo NVARCHAR(MAX)
SET @jsonInfo=N'{"info":{"address":[{"town":"Paris"},{"town":"London"}]}}';
SELECT JSON_PATH_EXISTS(@jsonInfo,'$.info.addresses'); -- 0