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 */,
"cases": {
/* "case_value": result_value */
},
"default": /* default value */
}

Returns​

Same as default value or one of the cases values

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimarystringYesValue to test
casesobjectA map of string to valueYes
defaultnullFallback 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