# $buildMap

`$buildMap` operator helps you in building a dynamic JSON object, where you can have conditional Key-Value pairs.

This is super useful when we need to optionally insert key-value pairs based on some conditions and do not want to build multiple If-Else blocks.

## Syntax

```json
{
    "$buildMap": [
        {
            "condition": <conditional_obj>,
            "key": <key_to_be_inserted>,
            "value": <value_to_be_inserted>
            }
        }
    ]
}
```

### Properties

<table><thead><tr><th>Field</th><th width="332">Description</th><th>Required</th></tr></thead><tbody><tr><td>condition</td><td><p>The <code>&#x3C;condition></code> can be any valid <a href="/pages/aJtci0lt5gcR4VOrIDr9"><mark style="color:blue;"><strong>condition object</strong></mark></a> as long as it resolves to a boolean object.</p><p></p><p>It can also be a <a href="/pages/RJ2ouQTCjKiUMsBHftne">Magical Autocomplete</a>.</p></td><td>true</td></tr><tr><td>key</td><td>The Key of the Key-Value pair to be inserted, if the condition holds true.</td><td>true</td></tr><tr><td>value</td><td>The Value of the Key-Value pair to be inserted, if the condition holds true.</td><td>true</td></tr></tbody></table>

### Returns

`json object` - The result of $buildMap operation, with Key-Value pairs.

## Examples

### Basic example

```json
{
    "$buildMap": [
        {
            "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 expression, assuming name & jobTitle is null but age is less than 10, returns an JSON object such as -

```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/cql-cosmocloud-query-language/building-expressions/usdbuildmap.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.
