For the complete documentation index, see llms.txt. This page is also available as Markdown.

Conditionals

Conditionals allow you to select different values depending on an expression. Dasel v3 supports an if/elseif/else block syntax and a ternary operator (?:).


Syntax

if (<condition>) { <then> } else { <else> }
  • <condition> must evaluate to a boolean.

  • <then> is evaluated if the condition is true.

  • <else> is evaluated if the condition is false.

  • An else branch is always required.


Basic Example

Input JSON

{
  "foo": {
    "bar": "baz",
    "bong": "selected",
    "qux": "not-selected"
  }
}

Query

Output


Elseif Chains

Use elseif to chain multiple conditions. You can use as many elseif branches as needed.

Example

Input JSON

Query

Output

Fizzbuzz with elseif

Given numbers.json:


Literal Results

Both branches can return literal values, not just field lookups.

Input JSON

Query

Output


Nested Conditionals

Conditionals can be nested in the else branch.

For multi-branch cases, elseif is cleaner than nesting.


Ternary Operator

The ternary operator provides a compact inline syntax for conditionals.

Syntax

  • <condition> must evaluate to a boolean.

  • <then> is returned when the condition is true.

  • <else> is returned when the condition is false.

Example

Input JSON

Query

Output

Nested Ternary

Parentheses can be used to nest ternary expressions.

Output


Notes

  • An else branch is always required — both if/else and if/elseif/else must have a final else.

  • Both branches must return a value — you cannot have an empty branch.

  • Use elseif (one word, no space) for chained conditions.

  • Parentheses around the condition are required for if/elseif blocks but not for the ternary operator.

  • The ternary operator always requires both ? and : parts.

Last updated