$$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": /* any */,
"else": null /* any */
}
"$$if(<then>,[else]):{input}"
note
Concrete values in the usage example are default values.
note
Alternative form is available using
{
"$$if": [ /* condition */, /* then */, /* else ? */]
}
If then
is used, the primary argument is treated as a condition
Returns​
Any
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | any | Yes | Condition | |
then | any | Yes | Value to return if condition is true | |
else | any | null | Value to return if condition is false |
Examples​
Input
Definition
Output
null
{
"$$if": [
true,
"b",
"c"
]
}
"b"
null
{
"$$if": [
true,
"b"
]
}
"b"
null
{
"$$if": [
false,
"b"
]
}
null
null
{
"$$if": [
null,
"b"
]
}
null
[
"a",
"b",
"c"
]
{
"$$if": [
"$[0]",
{
"$$if": [
"$[1]",
"d"
]
}
]
}
"d"
[
false,
0,
"true"
]
{
"$$if": [
"$[0]",
"d",
{
"$$if": [
"$[1]",
"d",
{
"$$if": [
"$[2]",
"d"
]
}
]
}
]
}
"d"
[
"a",
"b",
"c"
]
{
"$$if": [
"$[0]",
"$[1]",
"$[2]"
]
}
"b"
[
null,
"b",
"c"
]
{
"$$if": [
"$[0]",
"$[1]",
"$[2]"
]
}
"c"
[
"false",
"b",
"c"
]
{
"$$if": [
"$$boolean:$[0]",
"$[1]",
"$[2]"
]
}
"c"
[
true
]
{
"$$if": "$"
}
null
"hello"
{
"$$if": "$"
}
null
null
{
"$$if": true,
"then": "b",
"else": "c"
}
"b"
null
{
"$$if": true,
"then": "b"
}
"b"
null
{
"$$if": false,
"then": "b"
}
null
null
{
"$$if": "$",
"then": "b"
}
null
[
"a",
"b",
"c"
]
{
"$$if": "$[0]",
"then": {
"$$if": "$[1]",
"then": "d"
}
}
"d"
[
false,
0,
"true"
]
{
"$$if": "$[0]",
"then": "d",
"else": {
"$$if": "$[1]",
"then": "d",
"else": {
"$$if": "$[2]",
"then": "d"
}
}
}
"d"
[
"a",
"b",
"c"
]
{
"$$if": "$[0]",
"then": "$[1]",
"else": "$[2]"
}
"b"
[
null,
"b",
"c"
]
{
"$$if": "$[0]",
"then": "$[1]",
"else": "$[2]"
}
"c"
[
"false",
"b",
"c"
]
{
"$$if": "$$boolean:$[0]",
"then": "$[1]",
"else": "$[2]"
}
"c"
true
"$$if(a,b):$"
"a"
false
"$$if(a,b):$"
"b"
false
"$$if(a):$"
null