# Basic JSONATA boolean

**URL:** <https://discourse.nodered.org/t/basic-jsonata-boolean/92814>\
**Category:** General\
**Created:** [30 October 2024 20:52 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814 "2024-10-30T20:52:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonificator](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sonificator](https://discourse.nodered.org/u/sonificator)\
**Post date:** [30 October 2024 20:52 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/1 "2024-10-30T20:52:46Z")

</div>

Can't get most basic jsonata expression right in change node. I need to route mesage to two different outputs depending on the topic ... (topic = "A") seems to work but boolean (topic = "B" or topic = "C") doesn't. Thanks.

---

<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:** [30 October 2024 20:54 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/2 "2024-10-30T20:54:36Z")

</div>

If you want to route two different message types, not sure why you want a change node since this can be done with a switch node and without JSONata.

---

<div class="post-metadata">

**Author:** ![sonificator](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sonificator](https://discourse.nodered.org/u/sonificator)\
**Post date:** [30 October 2024 20:58 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/3 "2024-10-30T20:58:33Z")

</div>

I meant switch node. How do you route in case of (topic = "B" or topic = "C")

---

<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:** [30 October 2024 21:00 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/4 "2024-10-30T21:00:53Z")

</div>

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

Sorry, I did A, B and everything else. Adjust as needed of course. Also note that I've changed the setting at the bottom to stop after match rather than check all. Not sure how much difference this makes but it seems more logical to me and I wish it were the default to be honest.

---

<div class="post-metadata">

**Author:** ![sonificator](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sonificator](https://discourse.nodered.org/u/sonificator)\
**Post date:** [30 October 2024 21:02 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/5 "2024-10-30T21:02:54Z")

</div>

For first output 1 need it to be A (no problem with that), for output 2 I need to be B "or" C

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 October 2024 21:04 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/6 "2024-10-30T21:04:30Z")

</div>

Add all 3 & connect the B and C outputs together with a junction node or direct to the next node.

---

<div class="post-metadata">

**Author:** ![sonificator](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sonificator](https://discourse.nodered.org/u/sonificator)\
**Post date:** [30 October 2024 21:08 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/7 "2024-10-30T21:08:33Z")

</div>

Ok, or can just send B and C into the same place (without junction node)? I just wanted to do a jsonata boolean, didn't expect that wouldn't be able to solve it.

---

<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:** [30 October 2024 21:12 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/8 "2024-10-30T21:12:51Z")

</div>

> [@sonificator](#):
>
> can just send B and C into the same place (without junction node)?

Yes, certainly. A junction can be convenient though and may help keep the visuals tidy.

> [@sonificator](#):
>
> I just wanted to do a jsonata boolean, didn't expect that wouldn't be able to solve it.

JSONata can certainly do the job but it is a rather large industrial steam hammer to knock in a nail. 😄 JSONata adds significant overheads to your flow and is generally best kept for when nothing else fits or you need an object re-shaping (which is what it was originally for I believe).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2024 21:13 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/9 "2024-10-30T21:13:18Z")

</div>

You don't need a junction node, just feed the two outputs to the same place.

---

<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:** [30 October 2024 21:45 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/10 "2024-10-30T21:45:13Z")

</div>

> [@sonificator](#):
>
> I just wanted to do a jsonata boolean, didn't expect that wouldn't be able to solve it.

The output of $$.topic ="B" or $$.topic = "C" is a boolean so just add that as the expression.  
e.g.

```auto
[{"id":"01a5fa39c9c56b5a","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"A","payload":"1","payloadType":"str","x":870,"y":7760,"wires":[["5742f760b0672199"]]},{"id":"5742f760b0672199","type":"switch","z":"d1395164b4eec73e","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"A","vt":"str"},{"t":"jsonata_exp","v":"$$.topic = \"B\" or $$.topic = \"C\"","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":2,"x":1070,"y":7780,"wires":[["d890d64db2e56f8a"],["d09f296836f763f2"]]},{"id":"02b40896f488c50d","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"B","payload":"2","payloadType":"str","x":870,"y":7820,"wires":[["5742f760b0672199"]]},{"id":"f539489f4164f71c","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"C","payload":"3","payloadType":"str","x":870,"y":7880,"wires":[["5742f760b0672199"]]},{"id":"d890d64db2e56f8a","type":"debug","z":"d1395164b4eec73e","name":"debug 2575","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":7760,"wires":[]},{"id":"d09f296836f763f2","type":"debug","z":"d1395164b4eec73e","name":"debug 2576","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":7800,"wires":[]}]

```

Or if those are the only two outputs ("a" , "b" or "c") you could always use `otherwise` for second rule.

---

<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:** [13 November 2024 21:45 UTC](https://discourse.nodered.org/t/basic-jsonata-boolean/92814/11 "2024-11-13T21:45:50Z")

</div>

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