$$switch
Switch-case expression.
Value is compared to each of the keys in cases
and a matching key will result with its value,
otherwise default
value or null
will be returned.
Usage​
{
"$$switch": /* value */,
"cases": {
/* "case_value": result_value */
},
"default": /* default value */
}
Returns​
Same as default
value or one of the cases
values
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | string | Yes | Value to test | |
cases | object | A map of string to value | Yes | |
default | null | Fallback value in case no match to any key in cases |
Examples​
Input
Definition
Output
"B"
{
"$$switch": "$",
"cases": {
"a": 1,
"B": 2,
"c": 3
}
}
2
"D"
{
"$$switch": "$",
"cases": {
"a": 1,
"B": 2,
"c": 3
}
}
null
"D"
{
"$$switch": "$",
"cases": {
"a": 1,
"B": 2,
"c": 3
},
"default": 4
}
4
{
"a": 1,
"B": 2,
"c": 3
}
{
"$$switch": "B",
"cases": "$"
}
2