JSONata in arrays

Test string In array

The following expression tests if the value of msg.payload.section exists in the array:

Copy
payload.section in ['upload','table']

Lookup string in keys of array

JSONata provides the $lookup() function to retrieve the value associated with a key in an object.

Copy
$lookup(object, key)

If the first argument is an array of objects, $lookup() searches all objects in the array and returns the values associated with every occurrence of the key.

Suppose the following object is stored in msg.foobar:

Copy
{
    "foo": {
        "id": 123,
        "enabled": true
    },
    "bar": {
        "id": 456,
        "enabled": false
    }
}

To retrieve the value associated with the key "bar" in payload:

Copy
$lookup(foobar, "bar")

Result:

Copy
{
    "id": 456,
    "enabled": false
}

Tip: Many nodes in OL Connect Automate accept JSONata expressions. For sample expressions, see JSONata expression samples