Build Map

The Build Map node is used to create a new JSON / Object variable, with optional Key-Value pairs which should only be included if a certain condition is met.

This node is super helpful when we need to add keys based on certain conditions, such as existence in query params, etc so that we can build a dynamic object to query the database. Check the examples below for more inspiration.

Properties Panel

General

Returns

This node does not return any value, but sets a variable with your provided <name> in the flow context.

Examples

For example, if you have a Listing / Search API and would need to build a custom query object for the database (find or $match stage), you can use this node and provide the following list of buildmap objects -

[
    {
        "condition": {
            "$.request.queryParams.name": {
                "$neq": null
            }
        },
        "key": "name",
        "value": "$.request.queryParams.name"
    },
    {
        "condition": {
            "$.request.queryParams.jobTitle": {
                "$neq": null
            }
        },
        "key": "jobTitle",
        "value": "$.request.queryParams.jobTitle"
    },
    {
        "condition": {
            "$.request.queryParams.age": {
                "$ge": 10
            }
        },
        "key": "age",
        "value": "$.request.queryParams.age"
    }
]

The above buildmap objects list will iterate over each object to check if the condition is true or not, and if it is true, then will add the key-value pair to the following object.

Assuming above that name and jobTitle is not equal to null, but age is less than 10, this will result in a JSON variable as such -

{
    "name": "$.request.queryParams.name",
    "jobTitle": "$.request.queryParams.jobTitle"
}

Last updated