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

# JSON Conditions

> Writing JSON Logic conditions for reaction filters and claimable benefit eligibility in Omneo.

Omneo uses [JSON Logic](http://jsonlogic.com) for conditions in reaction filters and claimable benefit eligibility rules. JSON Logic is a small, portable specification for expressing rules as JSON.

## Basic syntax

A condition is a JSON object where the key is the operator and the value is an array of operands:

```json theme={null}
{ "operator": [left, right] }
```

The `{ "var": "field_name" }` expression reads a value from the event context.

## Single condition

Profile's first name is "Jane":

```json theme={null}
{ "===": [{"var": "first_name"}, "Jane"] }
```

## Comparison operators

| Operator | Meaning               |
| -------- | --------------------- |
| `===`    | Strictly equal        |
| `!==`    | Not equal             |
| `>`      | Greater than          |
| `>=`     | Greater than or equal |
| `<`      | Less than             |
| `<=`     | Less than or equal    |
| `in`     | Value exists in array |
| `!`      | Logical NOT           |

## OR condition

Profile has "tag-1" or "tag-2":

```json theme={null}
{
  "or": [
    { "in": ["tag-1", {"var": "flattened_tags"}] },
    { "in": ["tag-2", {"var": "flattened_tags"}] }
  ]
}
```

## AND condition

Birth year before 1980 AND tier is "tier-2":

```json theme={null}
{
  "and": [
    { "<": [{"var": "birth_year"}, 1980] },
    { "===": [{"var": "tier_handle"}, "tier-2"] }
  ]
}
```

12-month spend over \$1,000 AND in tier-2:

```json theme={null}
{
  "and": [
    { ">": [{"var": "aggregations.spend_12m"}, 1000] },
    { "===": [{"var": "tier_handle"}, "tier-2"] }
  ]
}
```

## NOT condition

Exclude profiles with "tag-1":

```json theme={null}
{ "!": {"in": ["tag-1", {"var": "flattened_tags"}]} }
```

Exclude profiles with "tag-1" AND "tag-2":

```json theme={null}
{
  "and": [
    { "!": {"in": ["tag-1", {"var": "flattened_tags"}]} },
    { "!": {"in": ["tag-2", {"var": "flattened_tags"}]} }
  ]
}
```

## Available variables

### Level 1: Profile fields (root level)

Accessed as `first_name`, `tier_handle`, `email`, etc.:

| Variable             | Type     | Example                     |
| -------------------- | -------- | --------------------------- |
| `first_name`         | string   | `"Jane"`                    |
| `last_name`          | string   | `"Smith"`                   |
| `email`              | string   | `"jane@example.com"`        |
| `tier_handle`        | string   | `"gold"`                    |
| `birth_year`         | integer  | `1985`                      |
| `birth_month`        | integer  | `9`                         |
| `birth_day`          | integer  | `15`                        |
| `gender`             | string   | `"female"`                  |
| `flattened_tags`     | array    | `["vip", "stylist-client"]` |
| `flattened_statuses` | array    | `["active"]`                |
| `reward_balance`     | number   | `25.00`                     |
| `point_balance`      | number   | `1500`                      |
| `joined_at`          | datetime | `"2023-01-15 00:00:00"`     |

### Level 2: Nested objects

Accessed with dot notation, e.g., `aggregations.spend_12m`:

| Variable                     | Type    | Description                                               |
| ---------------------------- | ------- | --------------------------------------------------------- |
| `aggregations.spend_12m`     | number  | Spend in last 12 months                                   |
| `aggregations.spend_all`     | number  | Lifetime spend                                            |
| `aggregations.spend_atv_12m` | number  | Average transaction value (12m)                           |
| `aggregations.shop_count`    | integer | Total transaction count                                   |
| `tier.handle`                | string  | Current tier handle                                       |
| `tier.name`                  | string  | Current tier name                                         |
| `definition.handle`          | string  | Handle of the triggering definition (tier, benefit, etc.) |

### Level 3: Deeply nested

Accessed as `attributes.comms.email_promo`, etc.:

| Variable                        | Type    | Description              |
| ------------------------------- | ------- | ------------------------ |
| `attributes.comms.email_promo`  | boolean | Email promotional opt-in |
| `attributes.comms.email_optout` | boolean | Email global opt-out     |
| `attributes.comms.sms_promo`    | boolean | SMS promotional opt-in   |

## Extended operators

Omneo extends standard JSON Logic with additional operators. They are available everywhere JSON Logic conditions run: reaction filters, [webhook conditions](/dev-guides/webhooks/webhooks#conditions), and claimable benefit eligibility rules.

### Comparison and filtering

| Operator              | Arguments                   | Returns true when                                                                               |
| --------------------- | --------------------------- | ----------------------------------------------------------------------------------------------- |
| `not_in`              | `[value, array]`            | The value is not in the array. On a string, checks the substring is absent                      |
| `non_empty_array`     | `[array]`                   | The array has at least one element                                                              |
| `array_length`        | `[array, operator, number]` | The array length satisfies the comparison. Operator is one of `==`, `!=`, `>`, `<`, `>=`, `<=`  |
| `array_has_key_value` | `[key, value, data]`        | Any object in the data, searched recursively, has the key with exactly that value               |
| `number_equal`        | `[left, right]`             | Both values are numerically equal, tolerating string-formatted numbers and thousands separators |

Example, transaction has at least two items:

```json theme={null}
{ "array_length": [{"var": "items"}, ">=", 2] }
```

### Date operators

| Operator        | Arguments                                               | Description                                                                                                                                                   |
| --------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `date_filter`   | `[value, operator, num, unit, timezone?]`               | Compares a date against now plus an offset. Operator is a comparison such as `lt`, `lte`, `gt`, `gte`, or `eq`. Unit is `days`, `weeks`, `months`, or `years` |
| `compare_dates` | `[value, compareValue, operator, num, unit, timezone?]` | Compares one date against another date plus an offset                                                                                                         |
| `get_date`      | `[value?, num?, unit?, timezone?]`                      | Returns a date string, defaulting to now, with an optional offset                                                                                             |
| `date_now`      | `[format, timezone?]`                                   | Returns the current date in the given PHP date format                                                                                                         |
| `date_format`   | `[value, format]`                                       | Reformats a date value                                                                                                                                        |

Example, profile joined more than 30 days ago:

```json theme={null}
{ "date_filter": [{"var": "joined_at"}, "lt", -30, "days"] }
```

### Value helpers

| Operator         | Arguments                                  | Description                                                                                           |
| ---------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
| `to_lower`       | `[value]`                                  | Lowercases a string, useful for case-insensitive comparison                                           |
| `to_upper`       | `[value]`                                  | Uppercases a string                                                                                   |
| `toFixed`        | `[value, decimals]`                        | Rounds a number to the given decimal places                                                           |
| `array_find_key` | `[key, array, default]`                    | Returns the value at a key, or the default when absent                                                |
| `array_find`     | `[array, key, value, default?, operator?]` | Returns the first item in the array whose key matches the value                                       |
| `extract`        | `[paths, data]`                            | Builds an object or array from dot-notation paths, with `*` wildcards for spreads and array iteration |
| `put`            | `[object, key, value]`                     | Returns the object with the key set to the value                                                      |
| `obj_merge`      | `[object, object, ...]`                    | Shallow-merges objects, later keys winning                                                            |

Example, match an email domain case-insensitively:

```json theme={null}
{ "in": ["@example.com", { "to_lower": [{"var": "email"}] }] }
```

## Full JSON Logic reference

For the complete standard operator reference, see [jsonlogic.com](http://jsonlogic.com). All standard JSON Logic operators are supported alongside the Omneo extensions above.
