# flat

Flattens a nested array by a specified depth level. Useful when working with arrays of arrays, such as results from `map` on nested data.

```liquid
{% assign all_tags = products | map: "tags" | flat %}
{% log all_tags %}
```

#### Syntax

```liquid
{{ array | flat }}
{{ array | flat: depth }}
```

| Parameter | Description                                          |
| --------- | ---------------------------------------------------- |
| `array`   | Array to flatten                                     |
| `depth`   | How many levels of nesting to flatten (default: `1`) |

#### Return Value

Returns a new array with nested arrays flattened to the specified depth.

#### Examples

**Flatten one level (default):**

```liquid
{% assign nested = "1,2|3,4|5,6" | split: "|" | map: "split", "," %}
{% assign flattened = nested | flat %}
{% log flattened %}
```

**Collect all tags from multiple products:**

```liquid
{% assign all_tags = products | map: "tags" | flat %}
{% assign unique_tags = all_tags | uniq %}
{% log unique_tags %}
```

**Flatten deeply nested arrays:**

```liquid
{% assign deep_flat = nested_array | flat: 2 %}
{% log deep_flat %}
```

**Collect all variant SKUs across products:**

```liquid
{% assign all_variants = products | map: "variants" | flat %}
{% assign all_skus = all_variants | map: "sku" %}
{% log all_skus %}
```

#### Notes

* Default depth is `1` — only the first level of nesting is flattened
* Non-array values are wrapped in an array before flattening
* Use higher depth values for deeply nested structures


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/filters/flat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
