Skip to main content

$$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 to test */,
"cases": /* object */,
"default": null /* any */
}
"$$switch(<cases>,[default]):{input}"
note

Concrete values in the usage example are default values.

Returns​

Same as default value or one of the cases values

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryanyYesValue to test
casesobjectYesA map of cases (string to value)
defaultanynullFallback 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
[
"B",
{
"a": 1,
"B": 2,
"c": 3
}
]
{
"$$switch": "$[0]",
"cases": "$[1]"
}
2
{
"a": 1,
"B": 2,
"c": 3
}
"$$switch($,'$$decimal:4'):B"
2
{
"a": 1,
"B": 2,
"c": 3
}
"$$switch($,'$$decimal:4'):C"
4