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

# Expressions

Workflow conditions accept **JavaScript expressions wrapped in double curly braces**``(`{{ ... }}`)`` to dynamically evaluate logic. These expressions are enclosed in double curly braces ``(`{{ ... }}`)`` and evaluated at runtime.

Expressions can access:

* Data from previous steps (`$json`, `$prev`, etc.)
* The loop context
* Built-in functions and utility libraries

For example, this checks if a status is `"active"`:

```js theme={null}
{{ $json["status"] === "active" }}
```

Expressions must be written as a single line of JavaScript. Multi-line code or variable declarations are not supported.

## Expression inputs

You can access the following contextual data inside expressions:

| Token      | Description                                       |
| ---------- | ------------------------------------------------- |
| `$json`    | The JSON object from the current or previous step |
| `$prev`    | Data from the previous node                       |
| `DateTime` | Utility for working with dates and times (Luxon)  |

Example:

```js theme={null}
{{ $json.customer.subscription.status === "trialing" }}
```

## Type conversion tip

Some values (such as "true" or "false") are returned as strings. To ensure your conditions behave as expected, you can enable **Convert types where required** in the Condition node settings.

Without type conversion:

```js theme={null}
{{ $json["isTrialActive"] }}
// Evaluates to string "true", which may not behave like a boolean
```

With type conversion enabled:

```js theme={null}
{{ $json["isTrialActive"] === "true" }}
```

Alternatively:

```js theme={null}
{{ Boolean($json["isTrialActive"]) }}
```

### Example: Remove addon from a subscription

At the end of a billing period, remove a specific addon from a subscription if it exists.

1. Run this workflow on a schedule or based on a billing-related event.

2. Use the List Subscriptions action to retrieve active subscriptions.

3. Use a loop node to iterate through the returned subscriptions.

4. For each subscription, loop through its `addons` array.

5. Condition Check

Use a Condition node to check if a specific addon is present:

```js theme={null}
{{ $json["addonId"] === "target-addon-id" }}
```

6. Update Subscription

If the addon exists, update the subscription using the Update Subscription action:

* **Subscription ID**: Pass from the previous loop context
* **Addons**: Supply a filtered list that excludes the unwanted addon

Example using a transformation node before update:

```js theme={null}
const filteredAddons = $json["addons"].filter(addon => addon.addonId !== "target-addon-id");
return { addons: filteredAddons };
```

To remove all addons, pass an empty array: `[]`.

## Using Luxon for date manipulation

The `DateTime` object is available for date handling inside expressions.

### Examples: get dates

Get today's ISO date:

```js theme={null}
{{ DateTime.now().toISODate() }}
```

Get the number of months between two dates:

```js theme={null}
{{ DateTime.fromISO('2025-07-01').diff(DateTime.fromISO('2025-04-01'), 'months').toObject() }}
```

<Note>
  Multi-line code blocks and variable declarations are not allowed in expressions.
</Note>

#### Invalid (multi-line code block)

```js theme={null}
{{
  let start = DateTime.fromISO('...');
  let end = DateTime.fromISO('...');
  return end.diff(start, 'days');
}}
```

#### Valid (single-line expression)

```js theme={null}
{{ DateTime.fromISO('2025-07-01').diff(DateTime.fromISO('2025-06-01'), 'days').toObject() }}
```

### Example: Extract nested JSON values

If your input JSON contains nested fields, you can access them like this:

```js theme={null}
{{ $json["body"]["user"]["location"] }}
```

Or with optional chaining:

```js theme={null}
{{ $json?.body?.user?.location }}
```

### Troubleshooting common issues

| Issue                        | Solution                                                             |
| ---------------------------- | -------------------------------------------------------------------- |
| Condition fails unexpectedly | Enable “Convert types where required” or check your type comparisons |
| Expression returns undefined | Make sure the key path is correct; use optional chaining (`?.`)      |
| Cannot reference a value     | Confirm the value exists in the current execution context (`$json`)  |
| Date math errors             | Use ISO-formatted strings and the `DateTime` library                 |
