$$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​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | array | Yes | Condition | |
then | Yes | Value to return if condition is true | ||
else | null | Value to return if condition is false |
Alternative form​
{
"$$if": [ /* condition */, /* then */, /* else ? */]
}
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | array | Yes | Array 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"