Variable Operators

Variable operators allow you to access data from the input object in your rules.

Overview

DataLogic-rs provides modern variable operators for accessing and validating data:

  • val - (Recommended) Access data from the input object using a path
  • exists - (Recommended) Check for the existence of fields in the data
  • var - (Legacy) Access data from the input object using a path
  • missing - (Legacy) Check for missing fields in the data
  • missing_some - (Legacy) Check if a minimum number of fields are present

Note: The legacy operators (var, missing, missing_some) will be removed in future versions. It's recommended to use val and exists instead.

val
exists
var (legacy)
missing (legacy)
missing_some (legacy)

val

The val operator is the modern replacement for var. It allows you to access data from the input object using a path.

Syntax

{ "val": "hello" }

or to access a nested path:

{ "val": ["hello", "world"] }

or with a default value:

{ "val": ["path", default_value] }

Parameters

Parameter Description
path A string path or array of path segments to the variable in the data object
default_value (optional) Value to return if variable is not found

Example: Access Simple Variable

Rule:

Data:

Result:

Example: Access Nested Variable with Array Path

Rule:

Data:

Result:

Example: Access Array Value by Index

Rule:

Data:

Result:

exists

The exists operator checks if a field or path exists in the data object and returns a boolean result.

Syntax

{ "exists": "hello" }

or for a nested path:

{ "exists": ["hello", "world"] }

Parameters

Parameter Description
path A string path or array of path segments to check for existence

Example: Check If Field Exists

Rule:

Data:

Result:

Example: Check Nested Path Existence

Rule:

Data:

Result:

Example: Null Value Check

Rule:

Data:

Result:

Example: Form Validation Using exists

Rule:

Data:

Result:

var (Legacy)

Deprecated

The var operator is a legacy way to access data from the input object using a path. It will be removed in future versions. Please use val instead.

Syntax

{ "var": "path.to.variable" }

or with a default value:

{ "var": ["path.to.variable", default_value] }

Parameters

Parameter Description
path Path to the variable in the data object (can be dot notation)
default_value (optional) Value to return if variable is not found

Example: Access Simple Variable

Rule:

Data:

Result:

Example: Access Nested Variable

Rule:

Data:

Result:

Example: Variable with Default Value

Rule:

Data:

Result:

missing (Legacy)

Deprecated

The missing operator is a legacy way to check for missing fields in the data object. It will be removed in future versions. Please use exists instead.

Syntax

{ "missing": ["field1", "field2", ...] }

Parameters

Parameter Description
fields Array of field paths to check

Example: Check Missing Fields

Rule:

Data:

Result:

Example: Form Validation

Rule:

Data:

Result:

missing_some (Legacy)

Deprecated

The missing_some operator is a legacy way to check if a minimum number of fields are present. It will be removed in future versions. Please use exists with additional logic instead.

Syntax

{ "missing_some": [min_required, ["field1", "field2", ...]] }

Parameters

Parameter Description
min_required Minimum number of fields required
fields Array of field paths to check

Example: Contact Information Validation

Rule:

Data:

Result:

Example: Optional Fields with Conditionals

Rule:

Data:

Result: