# Can someone explain why this switch node is not working ? (NR 4.02)

**URL:** <https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868>\
**Category:** General\
**Created:** [12 December 2024 01:57 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868 "2024-12-12T01:57:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 December 2024 01:57 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/1 "2024-12-12T01:57:24Z")

</div>

Guys,

I have a switch node looking a value in a Context Object and when i do a (what i thought was a straight string comparison for ==) it does not match - when i change the switch to contains - it does match

I have checked with the vendor and they are not adding spaces - and when i copy the value into a text editor there do not appear to be and leading/trailing space - any ideas ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8dae30d65869288de64c53caef0c786cd3590c51.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f7bab898304c6ff02ff8795066129fb45698b13.png)

If i change the contains to == it does not match on either value

Craig

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [12 December 2024 02:30 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/2 "2024-12-12T02:30:11Z")

</div>

your variable is BOOLEAN not a string ... you have to use below instead

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a9bebab90aff35009249933aff2307f76eab4dd.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 December 2024 04:41 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/3 "2024-12-12T04:41:12Z")

</div>

Hmm I assumed it was coming in as a string but you are saying it is being turned into a boolean - or just that NR treats all of true/false as boolean

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [12 December 2024 05:17 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/4 "2024-12-12T05:17:01Z")

</div>

You have check your payload object to determine the field types.

boolean : true / false (no "true" or "false")  
string: whenever there are " " than you have strings  
numbers : any number INT or FLOAT

example:  
estimate: "FALSE" = string  
estimate: false = boolean  
estimate: 0 = number (not false)  
estimate: 1 = number (not true)  
estimate: "0" = string

the entire data stream may be received as a STRING but is getting changed into a object with different field types

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 December 2024 05:45 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/5 "2024-12-12T05:45:28Z")

</div>

Yep I have and it is flagged by the provider as text and appears as that in the object - guess NR just makes some assumptions based on field content

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [12 December 2024 06:08 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/6 "2024-12-12T06:08:10Z")

</div>

Your data stream is most likely a string formated according JSON-format, which clearly defines the data type (no assumptions from NR 😉 ) .. I often use [this link](https://jsonformatter.org/) to analyse/test JSON strings

JSON-String:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffb36c5494be2c2f66ebd88afde933dd85c0d801.png)

JSON-string (formatted):

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8e992ab95d5d42108fe4464a2a72cf6db780dd1.png)

object:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9b36e1f1d24a2e98c559f2594c8a4de3dec9947.png)

your object was clearly described by the JSON format (converted into object)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95a1458c55daa43ae7c0a2e91ba894c576802801.jpeg)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [15 December 2024 20:56 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/7 "2024-12-15T20:56:27Z")

</div>

Thanks guys

Had not looked at the system in so long (testament to NR !) that i was rusty - indeed it is a boolean - thanks for the suggestions

Craig

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 December 2024 20:22 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/8 "2024-12-17T20:22:50Z")

</div>

~~Hey Craig.  
Just in passing, and reading your question.  
You said `msg.payload[0].estimate` and checking if it is `true`.  
The second picture is the payload.  
Wouldn't it be `msg.payload[0].trafficInformation.estimate` ?  
Sorry, just wondering.~~

Looked again.... Forget it. I'm stupid.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 December 2024 20:23 UTC](https://discourse.nodered.org/t/can-someone-explain-why-this-switch-node-is-not-working-nr-4-02/93868/9 "2024-12-31T20:23:46Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
