Conditionals
Conditionals allow you to select different values depending on an expression.
Dasel v3 supports both a long form if/else block and a compact ternary operator.
Long Form (if/else)
if/else)The long form is more explicit and easier to read for complex conditions.
if (<condition>) { <then-expression> } else { <else-expression> }<condition>must evaluate to a boolean.<then-expression>is evaluated if the condition is true.<else-expression>is evaluated if the condition is false.
Example
Input JSON
{
"foo": {
"bar": "baz",
"bong": "selected",
"qux": "not-selected"
}
}Query
Output
Ternary Operator (? :)
? :)Not yet implemented.
The ternary form is shorter and useful for inline conditions.
Example
Input JSON
Query
Output
Literals and Nesting
Both forms support literals and nested expressions.
Example 1: Literal results
Input JSON
Query
Output
Example 2: Nested ternaries
Input JSON
Query
Output
Notes
An
elsebranch is required. Both theif/elseand ternary forms must specify anelseresult.Both branches must return a value. A conditional always evaluates to a result — you cannot have an empty branch.
Parentheses are recommended when nesting conditionals.
Both branches must be valid dasel expressions (selectors, literals, or functions).
Last updated