# Recursive Descent

The **recursive descent operator** (`..`) allows you to search deeply through the entire document tree, starting at the current node, and return all matching keys, indices, or values.

This operator is most commonly used to extract values from **nested objects** and **arrays** without knowing their exact path.

***

### Syntax

```
..KEY
```

Return an array of all values of the given `KEY`, recursively.

```
..[INDEX]
```

Returns an array of the element at `INDEX` for every array found, recursively.

```
..*
```

Returns an array of **all values** (map values, array elements, scalars) at any depth.

***

### Behaviour

* `..` performs a depth-first traversal of the current node.
* For objects/maps:
  * `..KEY` finds all values where the key is `KEY`.
  * `..*` finds all values (for all keys).
* For arrays:
  * `..[INDEX]` selects the element at `INDEX` from every array found.
  * `..*` selects every element from every array found.
* Scalars (strings, numbers, booleans, nulls) are included when using `..*`.

***

### Examples

#### Example Input

```json
{
  "user": {
    "name": "Alice",
    "roles": ["admin", "editor"],
    "meta": {
      "active": true,
      "score": 42
    }
  },
  "tags": ["x", "y"],
  "count": 10
}
```

***

#### 1. Recursive Key Search

Get all values with the key `name`:

```bash
'..name'
```

Output:

```json
["Alice"]
```

***

#### 2. Recursive Array Index Search

Get the **first element** (`[0]`) of every array:

```bash
'..[0]'
```

Output:

```json
["admin", "x"]
```

***

#### 3. Recursive Wildcard (`..*`)

Get **all values at any depth**:

```bash
'..*'
```

Output:

```json
[
  "Alice",
  "admin",
  "editor",
  true,
  42,
  "x",
  "y",
  10
]
```

***

### Notes

* `..` is shorthand for recursive search by key or index.
* For more complex filtering (e.g. values where a key exists, or by type), use the [`search` ](https://daseldocs.tomwright.me/functions/search)operator.
* The `..` operator is widely known as the **recursive descent operator**, and is similar to:
  * `//` in XPath
  * `..` in JSONPath and yq
  * `..` in jq


---

# 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://daseldocs.tomwright.me/syntax/recursive-descent.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.
