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

This condition has at most one condition comparison key.

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

Properties

FieldDescriptionRequired

<key>

The key which needs to be compared with the value. This can also be a Magical Autocomplete.

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 here.

true

<value>

The value to compare the <key> with. This can also be a Magical Autocomplete.

Compound Condition

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

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

Properties

FieldDescriptionRequired

<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 here.

true

<cond>

A nested Simple Condition object or Compound Condition object.

true

Examples

Simple Conditions

{
    "$.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 -

# Sample query to be built
name=Shrey OR age=10
// 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 -

# Sample query to be built
name=Shrey OR (age>25 AND marks >=80)
// Condition Object
{
    "$or": [
        {
            "$.variables.name": {
                "$eq": "Shrey"
            }
        },
        {
            "$and": [
                {
                    "$.variables.age": {
                        "$gt": 25
                    }
                },
                {
                    "$.variables.marks": {
                        "$gte": 80
                    }
                }
            ]
        }
    ]

}

List of Compound Operators available in CQL -

List of Conditional Operators available in CQL -

Last updated