Skip to the content.

Logical Operators

Boolean logic and conditional execution operators.

and - Logical AND

Returns true only if all conditions are truthy. Short-circuits (stops evaluating) on first falsy value.

Syntax

{"and": [condition1, condition2, ...]}

Parameters

Return Type

Any - Returns the first falsy value, or the last value if all are truthy

Examples

Basic AND:

// Data: {"age": 25, "verified": true}
{"and": [
  {">": [{"var": "age"}, 18]},
  {"var": "verified"}
]}
//  true (both conditions met)

Short-circuit evaluation:

{"and": [false, {"var": "never.evaluated"}]}
//  false (stops at first false, doesn't error on missing path)

Multiple conditions:

{"and": [
  {">": [{"var": "score"}, 70]},
  {"<": [{"var": "score"}, 100]},
  {"==": [{"var": "status"}, "active"]}
]}
//  true only if all three conditions are true

Truthiness Rules

Optimization

Nested and operations are automatically flattened during compilation:

{"and": [{"and": [a, b]}, c]}  // Optimized to: {"and": [a, b, c]}

or - Logical OR

Returns true if any condition is truthy. Short-circuits on first truthy value.

Syntax

{"or": [condition1, condition2, ...]}

Parameters

Return Type

Any - Returns the first truthy value, or the last value if all are falsy

Examples

Basic OR:

// Data: {"premium": false, "trial": true}
{"or": [
  {"var": "premium"},
  {"var": "trial"}
]}
//  true (trial is truthy)

Default values with OR:

{"or": [
  {"var": "username"},
  {"var": "email"},
  "Guest"
]}
// Returns first available value or "Guest"

Multiple fallbacks:

{"or": [
  {"var": "primary.value"},
  {"var": "secondary.value"},
  {"var": "tertiary.value"},
  0
]}

Optimization

Nested or operations are automatically flattened:

{"or": [{"or": [a, b]}, c]}  // Optimized to: {"or": [a, b, c]}

not / ! - Logical NOT

Inverts the truthiness of a value.

Syntax

{"not": value}
{"!": value}
{"!": [value]}

Parameters

Return Type

Boolean - Always returns true or false

Examples

Basic negation:

{"!": true}   //  false
{"!": false}  //  true
{"!": 0}      //  true (0 is falsy)
{"!": 1}      //  false (1 is truthy)

Negate comparisons:

{"!": {">": [{"var": "age"}, 65]}}
// Same as: {"<=": [{"var": "age"}, 65]}

Check for missing:

{"!": {"var": "optional.field"}}
// Returns true if field is missing or falsy

Optimization

Double negation is automatically eliminated:

{"!": {"!": value}}  // Optimized to: value

if - Conditional Expression

Evaluates condition and returns one of two branches.

Syntax

{"if": [condition, then_value, else_value]}

Parameters

Return Type

Any - Returns either then_value or else_value

Examples

Basic conditional:

// Data: {"age": 25}
{"if": [
  {">": [{"var": "age"}, 18]},
  "Adult",
  "Minor"
]}
//  "Adult"

Nested conditions:

{"if": [
  {"<": [{"var": "age"}, 13]},
  "Child",
  {"if": [
    {"<": [{"var": "age"}, 18]},
    "Teen",
    "Adult"
  ]}
]}

With calculations:

{"if": [
  {"var": "premium"},
  {"*": [{"var": "price"}, 0.8]},  // 20% discount
  {"var": "price"}                 // Regular price
]}

Conditional array access:

{"if": [
  {">": [{"length": {"var": "items"}}, 0]},
  {"var": "items.0"},
  null
]}

Notes


xor - Exclusive OR

Returns true if exactly one of two conditions is truthy (not both, not neither).

Syntax

{"xor": [value1, value2]}

Parameters

Return Type

Boolean - true if exactly one value is truthy

Examples

Basic XOR:

{"xor": [true, false]}   //  true
{"xor": [true, true]}    //  false
{"xor": [false, false]}  //  false

Mutual exclusivity check:

// Data: {"cash": true, "credit": false}
{"xor": [{"var": "cash"}, {"var": "credit"}]}
//  true (exactly one payment method selected)

Toggle logic:

{"xor": [
  {"var": "settings.darkMode"},
  {"var": "settings.systemDefault"}
]}

ifnull - Null Coalescing

Returns the first value if it’s not null-like, otherwise returns the alternative.

Syntax

{"ifnull": [value, alternative]}

Parameters

Return Type

Any - Either value or alternative

Examples

Basic null check:

// Data: {"name": null}
{"ifnull": [{"var": "name"}, "Unknown"]}
//  "Unknown"

Chain multiple fallbacks:

{"ifnull": [
  {"var": "primary"},
  {"ifnull": [
    {"var": "secondary"},
    "default"
  ]}
]}

With calculations:

{"ifnull": [
  {"var": "customRate"},
  0.05  // Default rate
]}

Null-like Values

Treated as null:

Not treated as null:


isempty - Empty Check

Checks if a value is null or an empty string.

Syntax

{"isempty": value}

Parameters

Return Type

Boolean - true if value is null or empty string

Examples

Check for empty:

{"isempty": ""}      //  true
{"isempty": null}    //  true
{"isempty": "text"}  //  false
{"isempty": 0}       //  false
{"isempty": []}      //  false

Validate required field:

{"if": [
  {"isempty": {"var": "username"}},
  "Username is required",
  "Valid"
]}

Combined with NOT:

{"!": {"isempty": {"var": "optional.field"}}}
// Returns true if field has a value

empty - Empty String Literal

Returns an empty string constant.

Syntax

{"empty": null}

Return Type

String - ""

Examples

Return empty string:

{"empty": null}  //  ""

Conditional empty:

{"if": [
  {"var": "show"},
  {"var": "message"},
  {"empty": null}
]}

String building:

{"cat": [
  {"var": "prefix"},
  {"empty": null},
  {"var": "suffix"}
]}

Complex Examples

Access Control

{"and": [
  {"var": "user.authenticated"},
  {"or": [
    {"==": [{"var": "user.role"}, "admin"]},
    {"==": [{"var": "resource.owner"}, {"var": "user.id"}]}
  ]}
]}

Tiered Pricing

{"if": [
  {">": [{"var": "quantity"}, 100]},
  {"*": [{"var": "price"}, 0.7]},
  {"if": [
    {">": [{"var": "quantity"}, 50]},
    {"*": [{"var": "price"}, 0.85]},
    {"var": "price"}
  ]}
]}

Validation with Multiple Rules

{"and": [
  {"!": {"isempty": {"var": "email"}}},
  {">": [{"length": {"var": "password"}}, 8]},
  {"var": "terms_accepted"},
  {"xor": [
    {"var": "phone"},
    {"var": "backup_email"}
  ]}
]}

Best Practices

  1. Use short-circuit evaluation to avoid unnecessary work
    {"and": [{"var": "enabled"}, expensiveCalculation]}
    
  2. Prefer ifnull over nested if for null checks
    {"ifnull": [{"var": "value"}, "default"]}  //  Clear
    {"if": [{"var": "value"}, {"var": "value"}, "default"]}  //  Verbose
    
  3. Chain conditions logically
    {"and": [condition1, condition2, condition3]}  // 
    {"and": [condition1, {"and": [condition2, condition3]}]}  //  Unnecessary nesting
    
  4. Use isempty for string validation
    {"!": {"isempty": {"var": "required.field"}}}
    


Performance Notes