JSON_ARRAY_ELEMENTS (Lakehouse v1)
Extracts the elements from a JSON array, returning them as individual rows in the result set. JSON_ARRAY_ELEMENTS does not recursively expand nested arrays; it treats them as single elements.
Analyze Syntax
Section titled “Analyze Syntax”func.json_array_elements(<json_string>)Analyze Examples
Section titled “Analyze Examples”func.json_array_elements(func.parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]'))┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ func.json_array_elements(func.parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]')) │├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ {"brand":"Apple","price":1500,"product":"Laptop"} ││ {"brand":"Samsung","price":800,"product":"Smartphone"} ││ {"brand":"Sony","price":150,"product":"Headphones"} │└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘SQL Syntax
Section titled “SQL Syntax”JSON_ARRAY_ELEMENTS(<json_string>)Return Type
Section titled “Return Type”JSON_ARRAY_ELEMENTS returns a set of VARIANT values, each representing an element extracted from the input JSON array.
SQL Examples
Section titled “SQL Examples”-- Extract individual elements from a JSON array containing product informationSELECT JSON_ARRAY_ELEMENTS( PARSE_JSON ( '[ {"product": "Laptop", "brand": "Apple", "price": 1500}, {"product": "Smartphone", "brand": "Samsung", "price": 800}, {"product": "Headphones", "brand": "Sony", "price": 150}]' ) );
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ json_array_elements(parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]')) │├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ {"brand":"Apple","price":1500,"product":"Laptop"} ││ {"brand":"Samsung","price":800,"product":"Smartphone"} ││ {"brand":"Sony","price":150,"product":"Headphones"} │└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Display data types of the extracted elementsSELECT TYPEOF ( JSON_ARRAY_ELEMENTS( PARSE_JSON ( '[ {"product": "Laptop", "brand": "Apple", "price": 1500}, {"product": "Smartphone", "brand": "Samsung", "price": 800}, {"product": "Headphones", "brand": "Sony", "price": 150}]' ) ) );
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ typeof(json_array_elements(parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]'))) │├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ VARIANT NULL ││ VARIANT NULL ││ VARIANT NULL │└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘