JSON_EACH (Lakehouse v1)
Extrait les paires clé-valeur d’un objet JSON et décompose la structure en lignes distinctes dans le jeu de résultats. Chaque ligne représente une paire clé-valeur distincte issue de l’expression JSON en entrée.
Syntaxe Analyze
Section intitulée « Syntaxe Analyze »func.json_each(<json_string>)Exemples Analyze
Section intitulée « Exemples 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"') │└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘Syntaxe SQL
Section intitulée « Syntaxe SQL »JSON_EACH(<json_string>)Type de retour
Section intitulée « Type de retour »JSON_EACH renvoie un ensemble de tuples, chacun composé d’une clé de type STRING et de la valeur VARIANT correspondante.
Exemples SQL
Section intitulée « Exemples 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 │└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘