Boolean

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

Configuration

Result
Expression

(And) Does the array of data contain both a name and an image?

=$boolean(@ctx.datasources.employees.name and @ctx.datasources.employees.img)

(Or) Does the array of data contain a phone number or email?

=$boolean(@ctx.datasources.employees.phoneNumber or @ctx.datasources.employees.email)

(If value =) If the name of the employee is "Mary Gomez", set true

[email protected] = "Mary Gomez" ? true :false

(If value <) If the age of an employee is smaller than 20 set true.

[email protected] < 20 ? true :false

(If array >) Does the array of data contain more than two objects?

=$count(@ctx.datasources.employees) > 2 ? true :false

Examples and code snippets

Evaluating fields

Boolean expression
Boolean expression

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.

boolean.jigx
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: [email protected] = "Mary Gomez" ? true :false
        - type: component.entity-field
          options:
            label: If age of employee is smaller than 20 set true. (If value <)
            value: [email protected] < 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 

Placeholder

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.

See tips and tricks when using placeholders for additional information.

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

Last updated

Was this helpful?