PARSE_JSON (Lakehouse v1)
parse_json y try_parse_json interpretan una cadena de entrada como un documento JSON y producen un valor VARIANT.
try_parse_json devuelve un valor NULL si se produce un error durante el análisis.
Sintaxis de Analyze
Sección titulada «Sintaxis de Analyze»func.parse_json(<json_string>)
or
func.try_parse_json(<json_string>)Ejemplos de Analyze
Sección titulada «Ejemplos de 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} │└──────────────────────────────────────────────────────────────┘Sintaxis SQL
Sección titulada «Sintaxis SQL»PARSE_JSON(<expr>)TRY_PARSE_JSON(<expr>)Argumentos
Sección titulada «Argumentos»| Argumentos | Descripción |
|---|---|
<expr> |
Una expresión de tipo cadena (por ejemplo, VARCHAR) que contiene información JSON válida. |
Tipo de retorno
Sección titulada «Tipo de retorno»VARIANT
Ejemplos de SQL
Sección titulada «Ejemplos de 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} │└─────────────────────────────────────────────────────────┘