# Building Conditions

Conditions are JSON like objects which process and return a **boolean** output at the runtime. An expressions object looks like -

## Syntax

The condition can be build in 2 types -

* [Simple Condition](#simple-condition)
* [Compound Condition](#compound-condition)

### Simple Condition

This condition has **at most one** condition comparison key.

```json
{
    <key>: {
        <operator>: <value>
    }
}
```

#### Properties

| Field       | Description                                                                                                                                                                                                                                                | Required |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| \<key>      | <p>The key which needs to be compared with the value.<br><br>This can also be a Magical Autocomplete.</p>                                                                                                                                                  | true     |
| \<operator> | A CQL conditional operator which defines what type of comparison has to be done in this condition object. You can check the list of CQL conditions operators [<mark style="color:blue;">**here**</mark>](#list-of-conditional-operators-available-in-cql). | true     |
| \<value>    | <p>The value to compare the <code>\<key></code> with.<br><br>This can also be a Magical Autocomplete.</p>                                                                                                                                                  |          |

### Compound Condition

This condition can compound together multiple Simple and Compound Conditions together.

```
{
    <compound_operator>: [ <cond>, <cond>, ... ]
}
```

#### Properties

| Field                 | Description                                                                                                                                                                                                                                                     | Required |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| \<compound\_operator> | A CQL compound operator which defines what type of comparison has to be done between the list of nested conditions. You can check the list of CQL compound operators [<mark style="color:blue;">**here**</mark>](#list-of-compound-operators-available-in-cql). | true     |
| \<cond>               | A nested Simple Condition object or Compound Condition object.                                                                                                                                                                                                  | true     |

## Examples

### Simple Conditions

```json
{
    "$.variables.name": {
        "$eq": "Shrey"
    }
}
```

The above expression will return **true** if the variable `name` contains the value **Shrey** else will return **false**.

### Compound Conditions

The below snippet shows how you can build the query -&#x20;

```python
# Sample query to be built
name=Shrey OR age=10
```

```json
// Condition Object
{
    "$or": [
        {
            "$.variables.name": {
                "$eq": "Shrey"
            }
        },
        {
            "$.variables.age": {
                "$eq": 10
            }
        }
    ]

}
```

### Multiple Level of Conditions

The below snippet shows how you can build the query -&#x20;

```python
# Sample query to be built
name=Shrey OR (age>25 AND marks >=80)
```

```json
// Condition Object
{
    "$or": [
        {
            "$.variables.name": {
                "$eq": "Shrey"
            }
        },
        {
            "$and": [
                {
                    "$.variables.age": {
                        "$gt": 25
                    }
                },
                {
                    "$.variables.marks": {
                        "$gte": 80
                    }
                }
            ]
        }
    ]

}
```

List of Compound Operators available in CQL -

* [$and](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/compound-operators/usdand)
* [$or](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/compound-operators/usdor)

List of Conditional Operators available in CQL -

* [$eq](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/conditional-operators/usdeq)
* [$neq](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/conditional-operators/usdneq)
* [$lt](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/conditional-operators/usdlt)
* [$lte](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/conditional-operators/usdlte)
* [$gt](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/conditional-operators/usdgt)
* [$gte](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions/conditional-operators/usdgte)


---

# 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://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions.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.
