# Jsonata expression is not validated in Switch node Property field

**URL:** <https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195>\
**Category:** General\
**Created:** [11 September 2023 13:14 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195 "2023-09-11T13:14:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [11 September 2023 13:14 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/1 "2023-09-11T13:14:56Z")

</div>

If I put this Jsonata expression into a Change node the red border flags it as invalid  
 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/dea848ceafdc939a426a0c8193e926d53131f30b.gif)  
But in the Property field of a switch node there is no red border and the node is successfully deployed.

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/499a89ff371a83d0aed2eaaabd10f6c5c0aee266.gif)

However, the node presumably errors (silently) at runtime since there is no message output from either line.

 ![Untitled 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d198d389b77c7f2c11ff4a57734536398722071.gif)

```auto
[{"id":"9abbf6045584a050","type":"inject","z":"142f935612b6e391","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"BBB","payload":"AAA","payloadType":"str","x":120,"y":60,"wires":[["568c6a2a67c3b5d3"]]},{"id":"568c6a2a67c3b5d3","type":"switch","z":"142f935612b6e391","name":"","property":"{{payload}} & {{topic}}","propertyType":"jsonata","rules":[{"t":"eq","v":"AAABBB","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":60,"wires":[["43256a20bf961d71"],["b9990a554a15866e"]]},{"id":"43256a20bf961d71","type":"debug","z":"142f935612b6e391","name":"debug 398","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":40,"wires":[]},{"id":"b9990a554a15866e","type":"debug","z":"142f935612b6e391","name":"debug 399","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":80,"wires":[]}]

```

If the evaluation of a switch node expression gives an error, shouldn't evaluation continue to the next rather than just stopping?

Note that if you modify the internals of the change node and deploy, there is an error in the debug pane, but no red flag on the node. If you just move the node and deploy, no error message.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 September 2023 13:44 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/2 "2023-09-11T13:44:51Z")

</div>

Should that be `payload & topic`  
Flags {{payload}} & {{topic}} as invalid in switch node for me, node-red version 3.0.2  
The switch does not show red triangle though

 ![chrome_screenshot_1694440385479](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad03ab4dfe411b11095bda7fb30b2176c17dc5fa.png)  
 ![chrome_screenshot_1694440465314](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d77a9c3998e8629887adeb2bdc7e919762672384.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 September 2023 13:47 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/3 "2023-09-11T13:47:00Z")

</div>

When I import your flow into NR (v3.1.0) I get a error showing up in the debug sidebar:

 ![Screenshot 2023-09-11 at 9.36.10 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e25beb984aaac83779a3d289823e4af8756726d4.png)

Try this in the switch:  
 ![Screenshot 2023-09-11 at 9.46.08 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00d0598238e7745f232ae556364dbba44df4162a.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [11 September 2023 14:27 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/4 "2023-09-11T14:27:22Z")

</div>

> [@E1cid](#):
>
> Should that be `payload & topic`

Yes, thanks (both of you) I did eventually discover the right syntax, I was posting to report what seems to be a bug.

I'm not clear if the images you posted relate to run time or deploy.  
I did point out

> Note that if you modify the internals of the change node and deploy, there is an error in the debug pane, but no red flag on the node.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 September 2023 14:30 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/5 "2023-09-11T14:30:41Z")

</div>

Top 1 debug deploy switch only invalid expression, next is run with correct expression in switch only, then added change node, last 2 deploy both change and switch invalid expressions.  
Seems to be bug in switch not showing triangle, will upgrade to 3.1.0 next weekend, and check again, if somebody else has not already by then.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 September 2023 16:33 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/6 "2023-09-11T16:33:22Z")

</div>

Shows as an error for me:

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

v3.1.0

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 September 2023 16:46 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/7 "2023-09-11T16:46:08Z")

</div>

What about the red triangle on the node?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 September 2023 18:43 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/8 "2023-09-11T18:43:02Z")

</div>

No, that doesn't show. But I don't think a JSONata syntax error shows an invalid node on any node?

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

But they do give errors (to debug and console):

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/179a7bdd8d6ea36ef1cd31e9d8f95c9223013662.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 September 2023 18:45 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/9 "2023-09-11T18:45:45Z")

</div>

It does on a change node, see my images above.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 September 2023 19:41 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/10 "2023-09-11T19:41:57Z")

</div>

Indeed:

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [11 September 2023 20:20 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/11 "2023-09-11T20:20:10Z")

</div>

> [@TotallyInformation](#):
>
> Shows as an error for me:

OK yes, if I type `{{payload}} & {{topic}}` into either or both the Property field or a switch condition, the outline is red and at deploy there is a warning in the debug pane.  
**There is no red triangle flag on the node from either of these errors.**

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57d9bd5949fceba3bd4fd9cceef69f2c4d931b39.gif)

After deploy, back into the node, the border round the Property field is grey while the switch condition outline is still red (Property field is not verified when the node is opened?)

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0bd5431b044c78c7e101091c8af706bd7d440183.gif)

The moment I click in the Property field the border changes to blue (Bad assumption that validation has passed?)

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8dcccb01686bfdc63d4709be2c6b1812428bd2e7.gif)

It stays blue as I edit the field.

 ![Untitled 5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b5bc3f7c7fdf2849d1863d5138ea058345dfd41f.gif)

Observed on NR 3.1.0, not tested on 3.0.2

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 September 2023 20:46 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/12 "2023-09-11T20:46:17Z")

</div>

Confirmed.

You are correct, looks at least to be an inconsistent design if not a bug. 🙂

---

<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:** [10 November 2023 20:46 UTC](https://discourse.nodered.org/t/jsonata-expression-is-not-validated-in-switch-node-property-field/81195/13 "2023-11-10T20:46:21Z")

</div>

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