Prism · Structure
$case
Branches. They are tried in order: the first whose when is truthy gives its then, and else answers when none is.
{ score: 87 }{
$case: {
branches: [
{
when: { $gte: [{ $ref: '$.score' }, { $const: 90 }] },
then: { $const: 'A' },
},
{
when: { $gte: [{ $ref: '$.score' }, { $const: 80 }] },
then: { $const: 'B' },
},
{
when: { $gte: [{ $ref: '$.score' }, { $const: 70 }] },
then: { $const: 'C' },
},
],
else: { $const: 'F' },
},
}'B'
Runs in this page on the installed package. The input and the expected output are defined by the example.