JSONata - how to test if variable exists

I have a simple JSONata expression in a Switch node like below. It works as expected when the flow context variable is defined and set to 'on'. But how can I, with JSONata, check if a flow or global context variable really exists and is defined. I have tried null, empty, undefined...

image

$exists($globalContext('test'))	
2 Likes

Gary beat me to it... but I like a slightly different pattern:

image

Put the JSONata expression into the Property, and then use the output port rules as a kind of "case" statement (good for comparing incoming data to a list of possible string values, for example):

image

7 Likes

Brilliant Steve!

1 Like

Wonderful!! Thank you both of you, really helpful, my Switch works as I want now!
Best regards, Walter

1 Like