# 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

<table data-full-width="false"><thead><tr><th width="244">Field</th><th>Description</th><th>Required</th><th data-hidden>Default</th></tr></thead><tbody><tr><td>Node name</td><td><a href="/pages/jJ1qO0Ju8d7VFyPB2Jy3"><mark style="color:blue;"><strong>Checkout Node name</strong></mark></a></td><td>true</td><td>_</td></tr><tr><td>Variable name</td><td>Name of the JSON variable you need to create</td><td>true</td><td>_</td></tr><tr><td>List of BuildMap objects</td><td><p>A list of buildmap objects where each object mentions the condition based on which to add a certain key/value pair in the final JSON object.</p><p></p><p>You can use <a href="/pages/RJ2ouQTCjKiUMsBHftne">Magical Autocomplete</a> with keys, values and conditions.</p></td><td>true</td><td>_</td></tr></tbody></table>

### 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 -

```json
[
    {
        "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 -

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


---

# 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/node-types/variable-nodes/special/build-map.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.
