Skip to main content

$$if

Conditionally returns a value, if the evaluation of the condition argument is truthy (using the Truthy logic). A fallback value (if condition evaluates to false) is optional.

Usage​

{
"$$if": /* condition */,
"then": /* then value */,
"else": /* else value */
}

Returns​

Value of then or else

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesCondition
thenYesValue to return if condition is true
elsenullValue to return if condition is false

Alternative form​

{
"$$if": [ /* condition */, /* then */, /* else ? */]
}

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray of size 2 / 3

Examples​

Input

Definition

Output

{ "$$if": true, "then": "b", "else": "c" }
"b"
{ "$$if": [true, "b"] }
"b"
{ "$$if": false, "then": "b" }
null
{ "$$if": [null, "b"] }
null
{
"a": true,
"b": true
}
{ 
"$$if": [
"$.a",
{
"$$if": [
"$.b",
"a&b"
]
}
]
}
"a&b"
{ 
"a": false,
"b": true
}
{ 
"$$if": [
"$.a",
"a|b",
{
"$$if": [
"$.b",
"a|b"
]
}
]
}
"a|b"