Switch node issue

#1

Hi,

I'm trying to get the switch node to read in a json message from a sigfox callback and send a twillio message based on the data.

The messages can be of 3 types:
first type:
{
"data":"{c0}"

}
second type:
{
"data":"{c0ff}"

}
third type:
{
"data":"{c0ffee}"

}

what setup of the switch node would allow me to route the messages based on the data content. I tried the most logical combinations to my mind but I either get no routing or all 3 are routed.

*note : the message data is in hex I don't know if that changes anything If it does I can change it.
Any help would be greatly appreciated
image

0 Likes

#2

Hi @pixelview - welcome.

In your description you say the data properties are "{c0}" etc - but the screenshots show you testing for "c0". I assume the former is a typo?

I suggest you change the Property field of the switch node to be msg.payload.data and then you can use the == check for the string value c0 etc.

0 Likes

#3

Could you feed the data into a debug node and copy/paste the result please, to check exactly what the data consists of.

0 Likes

#4

Sorry about the confusion. This the data copied from debug {"data":"c0ff"}
image

0 Likes

#5

Right, so the payload is not JSON (which is a string) but is a javascript object. So in the switch node you just need, for example
msg.payload.data == "c0ff"
No JSON involved.

0 Likes

#6

It looks like the property should be set to msg.payload.data rather than just msg.payload, and then you would just compare with strings (not JSONata) - i.e. == c0, contains c0ff, or == c0ffee (it doesn't look like this last one should be a JSONata expression). Note that "c0ffee" would match the 2nd and 3rd case, so the result would depend on whether you have "checking all rules" or "stopping on first match" (in which case the 3rd would never occur).

0 Likes