> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usebruno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Response query

> Query and filter nested response data using dot notation, deep navigation, and array filtering

The `res` object available inside the [vars](../vars), [assertions](../../tests/assertions), [scripting](../getting-started), and [testing](../../tests/introduction) contexts can be invoked as a function to query nested response data.

Think of it as `lodash.get()` on steroids.

If you're not familiar, [`lodash.get()`](https://lodash.com/docs/#get) is a utility function from the [Lodash](https://lodash.com/) library that lets you safely access nested properties in JavaScript objects.

```javascript theme={null}
res('order.total')
```

<Info>
  Response query filtering (including `[?]` with filter functions and object predicates) works in both **Safe Mode** and **Developer Mode**.
</Info>

## Examples

```javascript theme={null}
const data = {
  customer: {
    address: {
      city: "bangalore"
    },
    orders: [
      {
        id: "order-1",
        items: [
          { id: 1, amount: 10 },
          { id: 2, amount: 20 }
        ]
      },
      {
        id: "order-2",
        items: [
          { id: 3, amount: 30 },
          { id: 4, amount: 40 }
        ]
      }
    ]
  },
};
```

| Query | Output |
| - | - |
| res("customer.address.city") | bangalore |
| res("customer.orders.items.amount") | \[10, 20, 30, 40] |
| res("customer.orders.items.amount\[0]") | 10 |
| res("..items.amount") | \[10, 20, 30, 40] |
| res("..amount") | \[10, 20, 30, 40] |
| res("..items.amount\[0]") | 10 |
| res("..items\[0].amount") | 10 |
| res("..items\[5].amount") | undefined |
| res("..id") | \["order-1", 1, 2, "order-2", 3, 4] |
| res("customer.orders.foo") | undefined |
| res("..customer.foo") | undefined |
| res("..address") | \[\{ city: "bangalore" }] |
| res("..address\[0]") | \{ city: "bangalore" } |

## API

### Standard dot notation

**Example:**

```javascript theme={null}
res('customer.orders.items.amount')
```

### Deep navigation with double dots

**Example:**

```javascript theme={null}
res('..items.amount')
```

### Array indexing

**Example:**

```javascript theme={null}
res('..items[0].amount')
```

### Array filtering with a filter function

Use `[?]` with a corresponding filter function to select matching items. `[?]` works with both standard dot notation and deep navigation (`..`).

**Example:**

```javascript theme={null}
res('customer.orders.items[?].amount', i => i.amount > 20)
res('..items[?].amount', i => i.amount > 20)
```

### Array filtering with an object predicate

Use `[?]` with an object to match items by property values. This is equivalent to `i => i.id === 2 && i.amount === 20`. `[?]` works with both standard dot notation and deep navigation (`..`).

```javascript theme={null}
res('customer.orders.items[?]', { id: 2, amount: 20 })
res('..items[?]', { id: 2, amount: 20 })
```

### Array mapping with a mapper function

Use `[?]` with a function that returns a transformed value to map over items. `[?]` works with both standard dot notation and deep navigation (`..`).

**Example:**

```javascript theme={null}
res('customer.orders.items..amount[?]', amt => amt + 10)
res('..items..amount[?]', amt => amt + 10)
```
