# LATERAL FLATTEN() Function

### Description

Unnests the ARRAY and JSON Object into individual rows

### Syntax

```sql
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

```sql
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);
```

Source: https://developer.rippling.com/documentation/rippling-platform/transformations/sql-reference/lateralflatten

> For the complete documentation index, see [llms.txt](https://developer.rippling.com/llms.txt). Public pages have a Markdown version at the same URL with .md added.
