JSON_EACH (Lakehouse v1)
Extracts key-value pairs from a JSON object, breaking down the structure into individual rows in the result set. Each row represents a distinct key-value pair derived from the input JSON expression.
Analyze Syntax
Section titled “Analyze Syntax”func.json_each(<json_string>)Analyze Examples
Section titled “Analyze Examples”┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ 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"') │└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘SQL Syntax
Section titled “SQL Syntax”JSON_EACH(<json_string>)Return Type
Section titled “Return Type”JSON_EACH returns a set of tuples, each consisting of a STRING key and a corresponding VARIANT value.
SQL Examples
Section titled “SQL Examples”-- 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 │└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘