Iterate

Required: no

This directive specifies the container of an array of items that the module must process and output. In its simplest form iterate directive is an IML String, which points to a container of your items (must be an array):

{
    "response": {
        "iterate": "{{body.data}}"
    }
}

When you need to filter out some items from processing, you are able to specify the iterate directive as an object, in which case it will have the following properties:

Key

Type

Description

Specifies the array with the data you want to process

Specifies a filter that can be used to filter out unwanted items

container

Required: yes

The iterate.container directive must point to an array of items that are to be processed.

See examples in Error Handling.

condition

Required: no Default: true

An optional expression to filter out unwanted items. Must resolve into a Boolean value, where true will pass the item through, and false will drop the item from processing. The item variable is available in this directive, which represents the current item being processed.

Important: The iterate directive changes the behavior of the output directive and allows you to use a special variable item that represents the currently processed item. The output directive will be executed for each item in the container that you have specified in iterate.container. You are able to use the item variable in the outputdirective to access properties of iterated objects.

For example, you are iterating this response:

{
    "success": true,
    "data": [{
        "id": 1,
        "foo": "bar"
    }, {
        "id": 2,
        "foo": "baz"
    }, {
        "id": 3,
        "foo": "qux"
    }]
}

Then, in order to process all items contained in the data array, you would specify your iterate directive like so:

{
    "response": {
        "iterate": "body.data",
        "output": {
            "id": "{{item.id}}",
            "text": "{{item.foo}}"
        }
    }
}

Here, in the output directive, you specify how you wish your output to look. The item variable represents the currently processed item from the data array. The output of this module will then be:

[{
    "id": 1,
    "text": "bar"
}, {
    "id": 2,
    "text": "baz"
}, {
    "id": 3,
    "text": "qux"
}]

Last updated