PARSE_JSON (Lakehouse v1)
parse_json et try_parse_json interprètent une chaîne en entrée comme un document JSON et produisent une valeur VARIANT.
try_parse_json renvoie une valeur NULL si une erreur se produit pendant l’analyse.
Syntaxe Analyze
Section intitulée « Syntaxe Analyze »func.parse_json(<json_string>)
or
func.try_parse_json(<json_string>)Exemples Analyze
Section intitulée « Exemples Analyze »func.parse_json('[-1, 12, 289, 2188, false]')
┌───────────────────────────────────────────────┐│ func.parse_json('[-1, 12, 289, 2188, false]') │├───────────────────────────────────────────────┤│ [-1,12,289,2188,false] │└───────────────────────────────────────────────┘
func.try_parse_json('{ "x" : "abc", "y" : false, "z": 10} ')
┌──────────────────────────────────────────────────────────────┐│ func.try_parse_json('{ "x" : "abc", "y" : false, "z": 10} ') │├──────────────────────────────────────────────────────────────┤│ {"x":"abc","y":false,"z":10} │└──────────────────────────────────────────────────────────────┘Syntaxe SQL
Section intitulée « Syntaxe SQL »PARSE_JSON(<expr>)TRY_PARSE_JSON(<expr>)Arguments
Section intitulée « Arguments »| Arguments | Description |
|---|---|
<expr> |
Une expression de type chaîne (par ex. VARCHAR) qui contient des informations JSON valides. |
Type de retour
Section intitulée « Type de retour »VARIANT
Exemples SQL
Section intitulée « Exemples SQL »SELECT parse_json('[-1, 12, 289, 2188, false]');┌──────────────────────────────────────────┐│ parse_json('[-1, 12, 289, 2188, false]') │├──────────────────────────────────────────┤│ [-1,12,289,2188,false] │└──────────────────────────────────────────┘
SELECT try_parse_json('{ "x" : "abc", "y" : false, "z": 10} ');┌─────────────────────────────────────────────────────────┐│ try_parse_json('{ "x" : "abc", "y" : false, "z": 10} ') │├─────────────────────────────────────────────────────────┤│ {"x":"abc","y":false,"z":10} │└─────────────────────────────────────────────────────────┘