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

# Expressions

> Literals, string interpolation, and reading object properties and list elements.

An expression is anything that produces a value: a literal, a variable, a property or element access, an [operator](/language/operators) applied to other expressions, or a [resource function call](/resources/overview). Use parentheses to group expressions.

## Object and list literals

Object literals list `key: value` pairs in curly braces. List literals list values in square brackets. Both can be nested and both allow a trailing comma.

```kotlin theme={null}
request Literals {
    const car = {
        brand: "Honda",
        owner: { name: "Ana" },
        tags: ["compact", "hybrid"],
    }
    const colors = ["red", "green", "orange",]
    return car
}
```

* Object keys are bare identifiers. Quoted keys such as `"brand": "Honda"` aren't supported.
* Keys must be unique within a single object literal.
* Values can be any expression, including variables and calculations: `{ total: price * quantity }`.

## String interpolation

Inside a string, `${expression}` evaluates any expression and inserts the result:

```kotlin theme={null}
request Interpolation {
    const name = "Ada"
    const items = 3
    return "Hello ${name}, you have ${items * 2} points"
    // "Hello Ada, you have 6 points"
}
```

Interpolated expressions can contain strings with their own interpolations: `"a ${"b ${c}"}"`.

Values are rendered as follows:

| Value | Rendered as |
| - | - |
| Numbers | Plain decimal notation, such as `42` or `0.3333333333` |
| Booleans | `true` or `false` |
| `null` | `null` |
| Objects and lists | JSON, such as `{"a":1,"b":[1,2]}` |

To include a literal `${` in a string, escape the dollar sign: `"Price: \${amount}"`.

## Reading object properties

Use dot notation to read a property:

```kotlin theme={null}
request Properties {
    const car = { brand: "Honda", owner: { name: "Ana" } }
    return car.owner.name // "Ana"
}
```

* Reading a property that doesn't exist returns `null`. It isn't an error.
* Reading a property of anything other than an object, such as a string or `null`, is an error.

> [!TIP]
>
> Because a missing property is `null`, you can check whether an object has a value with `!= null`:
>
> ```kotlin theme={null}
> if (order.coupon != null) {
>     // ...
> }
> ```

## Reading list elements

Use square brackets with a zero-based index to read a list element:

```kotlin theme={null}
request Elements {
    const colors = ["red", "green", "orange"]
    return colors[1] // "green"
}
```

* The index must be an integer.
* An index outside the list is an error, for example `List index 3 is out of bounds (list has 3 items)`.

Access can be chained: `orders[0].items[2].price`.

## Not available

RequestScript is deliberately small. It has no built-in functions or methods, so there's no way to get the length of a list or string, and no loops to iterate over a list. Logic that needs these is a good fit for a [resource](/resources/overview).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.