JSON_EACH (Lakehouse v1)
Extrai pares chave-valor de um objeto JSON, decompondo a estrutura em linhas individuais no conjunto de resultados. Cada linha representa um par chave-valor distinto derivado da expressão JSON de entrada.
Sintaxe do Analyze
Seção intitulada “Sintaxe do Analyze”func.json_each(<json_string>)Exemplos do Analyze
Seção intitulada “Exemplos do Analyze”┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ func.json_each(func.parse_json('{"name": "john", "age": 25, "isstudent": false, "grades": [90, 85, 92]}')) │├────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ ('age','25') ││ ('grades','[90,85,92]') ││ ('isStudent','false') ││ ('name','"John"') │└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘Sintaxe SQL
Seção intitulada “Sintaxe SQL”JSON_EACH(<json_string>)Tipo de retorno
Seção intitulada “Tipo de retorno”JSON_EACH retorna um conjunto de tuplas, cada uma composta por uma chave STRING e um valor VARIANT correspondente.
Exemplos de SQL
Seção intitulada “Exemplos de SQL”-- Extract key-value pairs from a JSON object representing information about a personSELECT JSON_EACH( PARSE_JSON ( '{"name": "John", "age": 25, "isStudent": false, "grades": [90, 85, 92]}' ) );
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐│ json_each(parse_json('{"name": "john", "age": 25, "isstudent": false, "grades": [90, 85, 92]}')) │├──────────────────────────────────────────────────────────────────────────────────────────────────┤│ ('age','25') ││ ('grades','[90,85,92]') ││ ('isStudent','false') ││ ('name','"John"') │└──────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Display data types of the extracted valuesSELECT TYPEOF ( JSON_EACH( PARSE_JSON ( '{"name": "John", "age": 25, "isStudent": false, "grades": [90, 85, 92]}' ) ) );
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ typeof(json_each(parse_json('{"name": "john", "age": 25, "isstudent": false, "grades": [90, 85, 92]}'))) │├──────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ TUPLE(STRING, VARIANT) NULL ││ TUPLE(STRING, VARIANT) NULL ││ TUPLE(STRING, VARIANT) NULL ││ TUPLE(STRING, VARIANT) NULL │└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘