JSON_PATH_MATCH (Lakehouse v1)
Vérifie si une expression de chemin JSON spécifiée correspond à certaines conditions dans des données JSON. À noter : l’opérateur @@ est synonyme de cette fonction. Pour en savoir plus, consultez les opérateurs JSON.
Syntaxe Analyze
Section intitulée « Syntaxe Analyze »func.json_path_match(<json_data>, <json_path_expression)Exemples Analyze
Section intitulée « Exemples Analyze »func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1')┌──────────────────────────────────────────────────────────────────────────┐│ func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1') │├──────────────────────────────────────────────────────────────────────────┤│ true │└──────────────────────────────────────────────────────────────────────────┘
func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1')┌────────────────────────────────────────────────────────────────────────────┐│ func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1') │├────────────────────────────────────────────────────────────────────────────┤│ false │└────────────────────────────────────────────────────────────────────────────┘Syntaxe SQL
Section intitulée « Syntaxe SQL »JSON_PATH_MATCH(<json_data>, <json_path_expression>)json_data: indique les données JSON à examiner. Il peut s’agir d’un objet JSON ou d’un tableau.json_path_expression: indique les conditions à vérifier dans les données JSON. Cette expression décrit le chemin ou les critères précis à faire correspondre, par exemple pour vérifier si certaines valeurs de champ de la structure JSON remplissent certaines conditions. Le symbole$représente la racine des données JSON. Il sert à démarrer l’expression de chemin et désigne l’objet de premier niveau de la structure JSON.
Type de retour
Section intitulée « Type de retour »La fonction renvoie :
truesi l’expression de chemin JSON spécifiée correspond aux conditions dans les données JSON.falsesi l’expression de chemin JSON spécifiée ne correspond pas aux conditions dans les données JSON.- NULL si
json_dataoujson_path_expressionest NULL ou invalide.
Exemples SQL
Section intitulée « Exemples SQL »-- Check if the value at JSON path $.a is equal to 1SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1');
┌────────────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1') │├────────────────────────────────────────────────────────────────┤│ true │└────────────────────────────────────────────────────────────────┘
-- Check if the first element in the array at JSON path $.b is greater than 1SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1');
┌──────────────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1') │├──────────────────────────────────────────────────────────────────┤│ false │└──────────────────────────────────────────────────────────────────┘
-- Check if any element in the array at JSON path $.b-- from the second one to the last are greater than or equal to 2SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[1 to last] >= 2');
┌───────────────────────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[1 to last] >= 2') │├───────────────────────────────────────────────────────────────────────────┤│ true │└───────────────────────────────────────────────────────────────────────────┘
-- NULL is returned if either the json_data or json_path_expression is NULL or invalid.SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), NULL);
┌──────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), null) │├──────────────────────────────────────────────────────────┤│ NULL │└──────────────────────────────────────────────────────────┘
SELECT JSON_PATH_MATCH(NULL, '$.a == 1');
┌───────────────────────────────────┐│ json_path_match(null, '$.a == 1') │├───────────────────────────────────┤│ NULL │└───────────────────────────────────┘