githubEdit

Operators

Dasel supports a range of operators for arithmetic, comparison, logic, assignment, and pattern matching.

Arithmetic Operators

Arithmetic operators work on numeric values (int and float). If either operand is a float, the result is a float.

Operator
Description
Example
Result

+

Addition

3 + 2

5

-

Subtraction

10 - 4

6

*

Multiplication

3 * 4

12

/

Division

10 / 3

3

%

Modulo

10 % 3

1

The + operator also works for string concatenation.

Examples

5 + 3    // 8
10 - 4   // 6
3 * 4    // 12
10 / 3   // 3 (integer division)
10 / 3.0 // 3.333... (float division)
10 % 3   // 1

Comparison Operators

Comparison operators return a boolean value.

Operator
Description
Example
Result

==

Equal

1 == 1

true

!=

Not equal

1 != 2

true

>

Greater than

3 > 2

true

>=

Greater than or equal

3 >= 3

true

<

Less than

2 < 3

true

<=

Less than or equal

3 <= 3

true

=~

Like (regex match)

"foo" =~ r/^f/

true

!~

Not like (regex no match)

"foo" !~ r/^b/

true

Examples

See Regex for more on pattern matching.

Logical Operators

Logical operators combine boolean expressions.

Operator
Description
Example
Result

&&

And

true && false

false

||

Or

true || false

true

Examples

Assignment Operator

The = operator assigns a value. It can be used to set variables, modify fields, or update array elements.

Operator
Description
Example

=

Assign

foo.bar = "new"

Examples

Set a variable

Modify a field

Modify in a loop

See Modifying data for more details.

Coalesce Operator

The ?? operator provides a fallback value when the left side is null, missing, or errors.

Operator
Description
Example

??

Coalesce

foo.bar ?? "default"

See Coalesce for full documentation.

Spread Operator

The ... operator unpacks arrays or maps into their individual elements.

Operator
Description
Example

...

Spread

[1, 2, 3].sum($this...)

See Spread for full documentation.

Last updated