Description
Unnests the ARRAY and JSON Object into individual rows
Syntax
LATERAL FLATTEN(expression, path, outer, recursive, mode)
Parameters
| Parameter | Description | Required |
|---|---|---|
| expression | The column or expression with a VARIANT, OBJECT, or ARRAY to flatten | Yes |
| path | JSONPath-like string specifying the path within the input to flatten (e.g. '$.items'). | No |
| outer | Boolean; if TRUE, returns a row with NULL if the input is empty or NULL; Default is FALSE | No |
| recursive | Boolean; if TRUE, flattens nested structures recursively. Default is FALSE | No |
| mode | String; can be 'object' or 'array'; Determines how input is flattened; Typically inferred automatically | No |
Notes
- JSON arrays need to be casted to ARRAY(JSON) before they can be flattened
Example
SELECT
flatten_val.someContrivedValue::VARCHAR, flatten_val.someContrivedKey
FROM
rippling.employee.Employee e
CROSS JOIN
LATERAL FLATTEN(
JSON_PARSE(CONCAT('{"someKey": " ', e.work_email, ' ", "someKey2": " ', e.full_name, ' "}'))
) AS flatten_val(someContrivedKey, someContrivedValue);