# Boolean

Within JSONata there are two types of Boolean expressions used to find out whether the result is true or false, namely:

1. [Boolean operators](https://docs.jsonata.org/boolean-operators) that include `and`, `or` [Boolean functions](https://docs.jsonata.org/boolean-functions) that include:
   * [$boolean()](https://docs.jsonata.org/boolean-functions#boolean)
   * [$not()](https://docs.jsonata.org/boolean-functions#not)
   * [$exists()](https://docs.jsonata.org/boolean-functions#exists)

## Configuration

<table><thead><tr><th width="273.3203125">Result</th><th>Expression</th></tr></thead><tbody><tr><td>(And) Does the array of data contain both a name and an image?</td><td><code>=$boolean(@ctx.datasources.employees.name and @ctx.datasources.employees.img)</code></td></tr><tr><td>(Or) Does the array of data contain a phone number or email?</td><td><code>=$boolean(@ctx.datasources.employees.phoneNumber or @ctx.datasources.employees.email)</code></td></tr><tr><td>(If value =) If the name of the employee is "Mary Gomez", set true</td><td><code>=@ctx.datasources.employee.name = "Mary Gomez" ? true :false</code></td></tr><tr><td>(If value &#x3C;) If the age of an employee is smaller than 20 set true.</td><td><code>=@ctx.datasources.employee.age &#x3C; 20 ? true :false</code></td></tr><tr><td>(If array >) Does the array of data contain more than two objects?</td><td><code>=$count(@ctx.datasources.employees) > 2 ? true :false</code></td></tr></tbody></table>

{% hint style="warning" %}
Be careful when using complex expressions, such as expressions that iterate one datasource across another, as your solution performance could become slower. To avoid this, try to use the datasource queries to get the desired result rather than an expression.
{% endhint %}

## Examples and code snippets

## Evaluating fields

{% columns %}
{% column %}

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FvSg7hSojghMAfXp1oWMK%2Fexp-boolean.png?alt=media&#x26;token=adeca9b9-4c5a-433d-be7f-23a69b838d93" alt="Boolean expression" width="188"><figcaption><p>Boolean expression</p></figcaption></figure>
{% endcolumn %}

{% column %}
This example evaluates static data in a `component.enity` to show the results in the entity field as a `boolean`.

See the full code sample in [GitHub](https://github.com/jigx-com/jigx-samples/blob/main/quickstart/jigx-samples/jigs/guide-expressions/static-data/boolean.jigx).
{% endcolumn %}
{% endcolumns %}

{% code title="boolean.jigx" %}

```yaml
children:
  - type: component.entity
    options:
      children:
        - type: component.entity-field
          options:
            label: Does the array of data contain both a name and an image? (And)
            value: =$boolean(@ctx.datasources.employees.name and @ctx.datasources.employees.img)
        - type: component.entity-field
          options:
            label: Does the array of data contain a phone number or email? (Or)
            value: =$boolean(@ctx.datasources.employees.phoneNumber or @ctx.datasources.employees.email)
        - type: component.entity-field
          options:
            label: If name of employee is "Mary Gomez", set true. (If value =)
            value: =@ctx.datasources.employee.name = "Mary Gomez" ? true :false
        - type: component.entity-field
          options:
            label: If age of employee is smaller than 20 set true. (If value <)
            value: =@ctx.datasources.employee.age < 20 ? true :false
        - type: component.entity-field
          options:
            label: Does the array of data contain more than two objects? (If array >)
            value: =$count(@ctx.datasources.employees) > 2 ? true :false 
```

{% endcode %}

## Placeholder

{% columns %}
{% column %}
Example of writing a condition for a placeholder. If the number of objects in the array is greater than zero, the placeholder is not displayed. If it isn't and the field is empty, a placeholder will appear with the icon and the specified text.

See the full code sample in [GitHub](https://github.com/jigx-com/jigx-samples/blob/main/quickstart/jigx-samples/jigs/guide-expressions/static-data/placeholder.jigx).

See [tips and tricks when using placeholders](https://community.jigx.com/t/tips-tricks-use-placeholders/78) for additional information.
{% endcolumn %}

{% column %}

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FNaDQvf6POme34Gt5RE0b%2Fexp-placeholder.png?alt=media&#x26;token=b6cd9549-131d-4e3a-9097-e5dbab2c4c6b" alt="Placeholder" width="188"><figcaption><p>Placeholder</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% code title="placeholder.jigx" %}

```yaml
placeholders:
  - when: =$count(@ctx.datasources.employees-dynamic) > 0 ? false :true 
    title: There is no data
    icon: missing-data
    
```

{% endcode %}


---

# 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.jigx.com/examples/readme/expressions/boolean.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.
