# Using a switch node with JSONata

**URL:** <https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867>\
**Category:** General\
**Created:** [14 November 2018 13:42 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867 "2018-11-14T13:42:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 13:42 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/1 "2018-11-14T13:42:56Z")

</div>

I'm using a switch and the input is msg.payload from a NetAtmo account. The payload object starts with:

```
{
    "compact": {
        "outdoor": {
            "temperature": 18.4,
            "humidity": 23,
            "battery_percent": 57,
            "rf_status": 60
        },
        "rain": {},
        "temperature": 22.7, ...

```

The #1 output is a JSONata expression:

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

But when deployed, nothing gets sent to the output.

Help.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 November 2018 14:18 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/2 "2018-11-14T14:18:46Z")

</div>

It will not be possible to help you unless you:

1- Fix the image that is not showing up in your post

2- Please provide the whole flow so we can have a look inside the switch node (as well as the dataset). Remember that to post code you need to add three backticks characters before and three backticks after the code.

````auto
```

````

Your code

````auto
```

````

---

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 14:36 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/3 "2018-11-14T14:36:00Z")

</div>

The limitation of new users only being able to post one image is a problem ...

The flow is simple:

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

`[{"id":"ba849ec9.74862","type":"inject","z":"3f0121a.5f1f7de","name":"","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":340,"wires":[["494665fe.6ad52c"]]},{"id":"494665fe.6ad52c","type":"netatmo-dashboard","z":"3f0121a.5f1f7de","creds":"3c55e9f5.f75e06","x":340,"y":340,"wires":[["3ba6b11e.29e53e"]]},{"id":"3ba6b11e.29e53e","type":"switch","z":"3f0121a.5f1f7de","name":"","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"compact.outdoor.temperature","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":340,"wires":[["867590c2.e3edd"]],"inputLabels":["xxx"],"outputLabels":["yyy"]},{"id":"867590c2.e3edd","type":"debug","z":"3f0121a.5f1f7de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":340,"wires":[]},{"id":"3c55e9f5.f75e06","type":"netatmo-config-node","z":"","client_id":"5ad1426a8e178263588b46d8","client_secret":"XXX","username":"XXX","password":"XXX"}]`

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 November 2018 14:38 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/4 "2018-11-14T14:38:18Z")

</div>

Can you wire the output of the NetAtmo node to a Debug node and show us its output?

---

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 14:40 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/5 "2018-11-14T14:40:16Z")

</div>

The output of the NetAtmo node is the payload object I showed above ...

```
{
    "compact": {
        "outdoor": {
            "temperature": 18.4,
            "humidity": 23,
            "battery_percent": 57,
            "rf_status": 60
        },
        "rain": {},
        "temperature": 22.7, ...
```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 November 2018 14:41 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/6 "2018-11-14T14:41:16Z")

</div>

If that is the payload of the message (which the Debug sidebar would have told us), then your jsonata expression needs to be `payload.compact.outdoor.temperature`.

---

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 14:44 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/7 "2018-11-14T14:44:55Z")

</div>

I tried that and there's still no switch output. That expression also fails in the expression editor using the NetAtmo output object.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 November 2018 14:52 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/8 "2018-11-14T14:52:01Z")

</div>

> [@quistuipater](#):
>
> That expression also fails in the expression editor using the NetAtmo output object.

In the screen shot of the expression editor, you have put the `compact` object at the top level of the message object. It is not under the `payload` property as I would expect it to be coming from the NetAtmo node.

You can use the Debug node to confirm the exact message structure you have.

---

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 14:54 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/9 "2018-11-14T14:54:44Z")

</div>

Here's the full NetAtmo payload object (the opening "(" gets cut off in the forum editor's rendering for some reason):

````auto
  "compact": {
    "outdoor": {
      "temperature": 15.2,
      "humidity": 19,
      "temperatureTrend": "stable",
      "battery_percent": 57,
      "rf_status": 71
    },
    "rain": {},
    "temperature": 20.7,
    "temperatureTrend": "stable",
    "co2": 486,
    "humidity": 37,
    "noise": 44,
    "pressure": 1026,
    "pressureTrend": "down",
    "station_name": "XXX",
    "last_status_store": 1542206768
  },
  "detailed": [
    {
      "_id": "70:ee:50:00:ea:18",
      "cipher_id": "XXX",
      "date_setup": 1371091374,
      "last_setup": 1371091374,
      "type": "NAMain",
      "last_status_store": 1542206768,
      "module_name": "XXX",
      "firmware": 132,
      "last_upgrade": 1440121433,
      "wifi_status": 50,
      "co2_calibrating": false,
      "station_name": "XXX",
      "data_type": [
        "Temperature",
        "CO2",
        "Humidity",
        "Noise",
        "Pressure"
      ],
      "place": {
        "altitude": 120.08533983542,
        "city": "XXX",
        "country": "US",
        "timezone": "XXX",
        "location": [
          XXX,
          XXX
        ]
      },
      "dashboard_data": {
        "time_utc": 1542206753,
        "Temperature": 20.7,
        "CO2": 486,
        "Humidity": 37,
        "Noise": 44,
        "Pressure": 1026,
        "AbsolutePressure": 1011.5,
        "min_temp": 20.6,
        "max_temp": 21.4,
        "date_min_temp": 1542204365,
        "date_max_temp": 1542182477,
        "temp_trend": "stable",
        "pressure_trend": "down"
      },
      "modules": [
        {
          "_id": "02:00:00:00:f8:c4",
          "type": "NAModule1",
          "module_name": "Outdoor",
          "data_type": [
            "Temperature",
            "Humidity"
          ],
          "last_setup": 1371091749,
          "dashboard_data": {
            "time_utc": 1542206723,
            "Temperature": 15.2,
            "Humidity": 19,
            "min_temp": 14.8,
            "max_temp": 17.3,
            "date_min_temp": 1542203724,
            "date_max_temp": 1542189727,
            "temp_trend": "up"
          },
          "firmware": 44,
          "last_message": 1542206762,
          "last_seen": 1542206723,
          "rf_status": 71,
          "battery_vp": 4965,
          "battery_percent": 57
        }
      ]
    }
  ]
}```
````

---

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 15:00 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/10 "2018-11-14T15:00:22Z")

</div>

And to make sure you believe that's the NetAtmo node output, here's an image of the expanded debug output (I removed the station name):

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

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 November 2018 15:22 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/11 "2018-11-14T15:22:15Z")

</div>

I find no issue to extract the temperature, in many different ways.

Please have a look in below flow.

 ![r-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/74d9acc59aff86a8a7bdba7f14e82e0090c45531.png)

Flow:

```auto
[{"id":"56970bdc.c12284","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"b90fcda6.e6b22","type":"inject","z":"56970bdc.c12284","name":"","topic":"","payload":"{\"compact\":{\"outdoor\":{\"temperature\":15.2,\"humidity\":19,\"temperatureTrend\":\"stable\",\"battery_percent\":57,\"rf_status\":71},\"rain\":{},\"temperature\":20.7,\"temperatureTrend\":\"stable\",\"co2\":486,\"humidity\":37,\"noise\":44,\"pressure\":1026,\"pressureTrend\":\"down\",\"station_name\":\"XXX\",\"last_status_store\":1542206768},\"detailed\":[{\"_id\":\"70:ee:50:00:ea:18\",\"cipher_id\":\"XXX\",\"date_setup\":1371091374,\"last_setup\":1371091374,\"type\":\"NAMain\",\"last_status_store\":1542206768,\"module_name\":\"XXX\",\"firmware\":132,\"last_upgrade\":1440121433,\"wifi_status\":50,\"co2_calibrating\":false,\"station_name\":\"XXX\",\"data_type\":[\"Temperature\",\"CO2\",\"Humidity\",\"Noise\",\"Pressure\"],\"place\":{\"altitude\":120.08533983542,\"city\":\"XXX\",\"country\":\"US\",\"timezone\":\"XXX\",\"location\":[\"XXX\",\"XXX\"]},\"dashboard_data\":{\"time_utc\":1542206753,\"Temperature\":20.7,\"CO2\":486,\"Humidity\":37,\"Noise\":44,\"Pressure\":1026,\"AbsolutePressure\":1011.5,\"min_temp\":20.6,\"max_temp\":21.4,\"date_min_temp\":1542204365,\"date_max_temp\":1542182477,\"temp_trend\":\"stable\",\"pressure_trend\":\"down\"},\"modules\":[{\"_id\":\"02:00:00:00:f8:c4\",\"type\":\"NAModule1\",\"module_name\":\"Outdoor\",\"data_type\":[\"Temperature\",\"Humidity\"],\"last_setup\":1371091749,\"dashboard_data\":{\"time_utc\":1542206723,\"Temperature\":15.2,\"Humidity\":19,\"min_temp\":14.8,\"max_temp\":17.3,\"date_min_temp\":1542203724,\"date_max_temp\":1542189727,\"temp_trend\":\"up\"},\"firmware\":44,\"last_message\":1542206762,\"last_seen\":1542206723,\"rf_status\":71,\"battery_vp\":4965,\"battery_percent\":57}]}]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":120,"wires":[["9ea08632.091e18","a6ef2b61.e87538","78fc3ea5.262be","fcea5f3d.3a6b2"]]},{"id":"9ea08632.091e18","type":"switch","z":"56970bdc.c12284","name":"","property":"payload.compact.outdoor.temperature","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":180,"wires":[["8087331a.f3de5"]],"inputLabels":["xxx"],"outputLabels":["yyy"]},{"id":"a6ef2b61.e87538","type":"debug","z":"56970bdc.c12284","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.compact.outdoor.temperature","x":510,"y":120,"wires":[]},{"id":"8087331a.f3de5","type":"debug","z":"56970bdc.c12284","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":180,"wires":[]},{"id":"78fc3ea5.262be","type":"change","z":"56970bdc.c12284","name":"Set result","rules":[{"t":"set","p":"result","pt":"msg","to":"payload.compact.outdoor.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":240,"wires":[["7695b562.09585c"]]},{"id":"7695b562.09585c","type":"debug","z":"56970bdc.c12284","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"result","x":610,"y":240,"wires":[]},{"id":"fcea5f3d.3a6b2","type":"change","z":"56970bdc.c12284","name":"Set output","rules":[{"t":"set","p":"output","pt":"msg","to":"payload.compact.outdoor.temperature","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":300,"wires":[["77af2f5a.c5a35"]]},{"id":"77af2f5a.c5a35","type":"debug","z":"56970bdc.c12284","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"output","x":610,"y":300,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 November 2018 15:25 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/12 "2018-11-14T15:25:33Z")

</div>

At the top of the screenshot it says `msg.payload` - so this whole `compact`object is under `msg.payload`.

If you hover over any message element, a button appears on the right side which can be used to copy the path to the element to your clipboard.

You'll find you get `payload.compact.outdoor.temperature`

That aside, the problem is your Switch node configuration. You are asking it to compare the value of `msg.payload` with the result of `compact.outdoor.temperature` .. which won't work.

What is the actual comparison you want to make?

Or do you want to set msg.payload to the value of `msg.payload.compact.outdoor.temperature` ? If that is what you want, you should use a Change node, not a Switch node.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 November 2018 15:37 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/13 "2018-11-14T15:37:34Z")

</div>

Note this explanation from the switch node help:

A JSONata Expression can be provided that will be evaluated against the whole message and will match **if the expression returns a true value**.

Perhaps you want to use this jsonata expression in your switch node ?

`payload.compact.outdoor.temperature > 0`

Flow:

```auto
[{"id":"d9ab29db.5928c8","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"9740667f.9f4988","type":"switch","z":"d9ab29db.5928c8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"payload.compact.outdoor.temperature > 0","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":120,"wires":[["fc75236b.53b84"]],"inputLabels":["xxx"],"outputLabels":["yyy"]},{"id":"fc75236b.53b84","type":"debug","z":"d9ab29db.5928c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":570,"y":120,"wires":[]},{"id":"605ed803.bdb988","type":"comment","z":"d9ab29db.5928c8","name":" **Explanation**","info":"A JSONata Expression can be provided that will be evaluated against the whole message and will match if the expression returns a true value.","x":200,"y":60,"wires":[]},{"id":"8f0b622e.a2e7a","type":"inject","z":"d9ab29db.5928c8","name":"","topic":"","payload":"{\"compact\":{\"outdoor\":{\"temperature\":15.2,\"humidity\":19,\"temperatureTrend\":\"stable\",\"battery_percent\":57,\"rf_status\":71},\"rain\":{},\"temperature\":20.7,\"temperatureTrend\":\"stable\",\"co2\":486,\"humidity\":37,\"noise\":44,\"pressure\":1026,\"pressureTrend\":\"down\",\"station_name\":\"XXX\",\"last_status_store\":1542206768},\"detailed\":[{\"_id\":\"70:ee:50:00:ea:18\",\"cipher_id\":\"XXX\",\"date_setup\":1371091374,\"last_setup\":1371091374,\"type\":\"NAMain\",\"last_status_store\":1542206768,\"module_name\":\"XXX\",\"firmware\":132,\"last_upgrade\":1440121433,\"wifi_status\":50,\"co2_calibrating\":false,\"station_name\":\"XXX\",\"data_type\":[\"Temperature\",\"CO2\",\"Humidity\",\"Noise\",\"Pressure\"],\"place\":{\"altitude\":120.08533983542,\"city\":\"XXX\",\"country\":\"US\",\"timezone\":\"XXX\",\"location\":[\"XXX\",\"XXX\"]},\"dashboard_data\":{\"time_utc\":1542206753,\"Temperature\":20.7,\"CO2\":486,\"Humidity\":37,\"Noise\":44,\"Pressure\":1026,\"AbsolutePressure\":1011.5,\"min_temp\":20.6,\"max_temp\":21.4,\"date_min_temp\":1542204365,\"date_max_temp\":1542182477,\"temp_trend\":\"stable\",\"pressure_trend\":\"down\"},\"modules\":[{\"_id\":\"02:00:00:00:f8:c4\",\"type\":\"NAModule1\",\"module_name\":\"Outdoor\",\"data_type\":[\"Temperature\",\"Humidity\"],\"last_setup\":1371091749,\"dashboard_data\":{\"time_utc\":1542206723,\"Temperature\":15.2,\"Humidity\":19,\"min_temp\":14.8,\"max_temp\":17.3,\"date_min_temp\":1542203724,\"date_max_temp\":1542189727,\"temp_trend\":\"up\"},\"firmware\":44,\"last_message\":1542206762,\"last_seen\":1542206723,\"rf_status\":71,\"battery_vp\":4965,\"battery_percent\":57}]}]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":120,"wires":[["9740667f.9f4988"]]}]

```

---

<div class="post-metadata">

**Author:** ![quistuipater](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quistuipater/32/3751_2.png) [@quistuipater](https://discourse.nodered.org/u/quistuipater)\
**Post date:** [14 November 2018 16:27 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/14 "2018-11-14T16:27:42Z")

</div>

I realize that I've misunderstood how JSONata works with the switch node. Gentlemen, many thanks for your help.

---

<div class="post-metadata">

**Author:** ![a8ree](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/a8ree/32/45947_2.png) [@a8ree](https://discourse.nodered.org/u/a8ree)\
**Post date:** [3 August 2021 10:12 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/16 "2021-08-03T10:12:03Z")

</div>

Sorry to resurrect a very old thread.  
I'm trying to do something very similar and thought I would copy this flow to understand how to do it.

I can see that the query is  
payload.compact.outdoor.temperature \> 0  
and that the value for this in the example is 20.7 - so it works as you decribed.

I've tried to change the query to  
payload.compact.outdoor.temperature = "20.7"  
as this aligns with what I am trying to achieve and I expected that this would match - but it doesn't. I have tried a couple of permutations but can't work this out.

Are you able to tell me where I am going wrong?

---

<div class="post-metadata">

**Author:** ![a8ree](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/a8ree/32/45947_2.png) [@a8ree](https://discourse.nodered.org/u/a8ree)\
**Post date:** [3 August 2021 10:14 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/17 "2021-08-03T10:14:11Z")

</div>

Ignore me.....it 15.2!

---

<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:** [3 August 2021 10:19 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/18 "2021-08-03T10:19:27Z")

</div>

> [@a8ree](#):
>
> payload.compact.outdoor.temperature = "20.7"

using `=` is an assignment and will result as 'true'. You would want to use `==` or `===`

---

<div class="post-metadata">

**Author:** ![a8ree](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/a8ree/32/45947_2.png) [@a8ree](https://discourse.nodered.org/u/a8ree)\
**Post date:** [3 August 2021 11:03 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/19 "2021-08-03T11:03:24Z")

</div>

Thanks - I now have this working in a switch node!

Incidentally, is it possible to achieve the same / similar where I am only looking for one value using a Current State node?

---

<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:** [3 August 2021 12:00 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/20 "2021-08-03T12:00:11Z")

</div>

You’ll have to explain a bit more, an example maybe??

---

<div class="post-metadata">

**Author:** ![a8ree](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/a8ree/32/45947_2.png) [@a8ree](https://discourse.nodered.org/u/a8ree)\
**Post date:** [3 August 2021 14:54 UTC](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867/21 "2021-08-03T14:54:42Z")

</div>

I've exported my two test flows

```auto
[{"id":"5f5de67.df35618","type":"change","z":"7a2dace0.8a2f84","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.ap_mac = \"b4:fb:e4:43:0f:7a\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":2100,"wires":[["37de49e8.6789b6"]]},{"id":"37de49e8.6789b6","type":"debug","z":"7a2dace0.8a2f84","name":"switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":2100,"wires":[]},{"id":"c73b81c0.72287","type":"api-current-state","z":"7a2dace0.8a2f84","name":"","server":"8ca832e4.1e6b4","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"device_tracker.unifi_92_40_6c_e1_5f_25_rkgtdu9r","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":690,"y":2180,"wires":[["5f5de67.df35618","a6aa00a4.00703"]]},{"id":"f11d0060.cc1d1","type":"inject","z":"7a2dace0.8a2f84","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":2180,"wires":[["c73b81c0.72287"]]},{"id":"a6aa00a4.00703","type":"debug","z":"7a2dace0.8a2f84","name":"from","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":2200,"wires":[]},{"id":"6842148c.dd679c","type":"api-current-state","z":"7a2dace0.8a2f84","name":"","server":"8ca832e4.1e6b4","version":2,"outputs":2,"halt_if":"data.attributes.ap_mac = \"b4:fb:e4:43:0f:7a\"","halt_if_type":"jsonata","halt_if_compare":"jsonata","entity_id":"device_tracker.unifi_92_40_6c_e1_5f_25_rkgtdu9r","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":710,"y":2340,"wires":[["bd6bc924.7b9008","edbb3c9c.4e0f6"],["edbb3c9c.4e0f6"]]},{"id":"4735b7ec.b22388","type":"inject","z":"7a2dace0.8a2f84","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":2340,"wires":[["6842148c.dd679c"]]},{"id":"bd6bc924.7b9008","type":"api-call-service","z":"7a2dace0.8a2f84","name":"ManCave Mobile","server":"8ca832e4.1e6b4","version":3,"debugenabled":false,"service_domain":"notify","service":"mobile_app_aidan_phone","entityId":"","data":"{\"message\":\"Mancave AP\",\"title\":\"New AP\",\"data\": {\"timeout\": 60}}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1090,"y":2340,"wires":[[]]},{"id":"edbb3c9c.4e0f6","type":"debug","z":"7a2dace0.8a2f84","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1100,"y":2420,"wires":[]},{"id":"8ca832e4.1e6b4","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

```

The first takes the current state and pushes it to the change node to evaluate whether the condition is met - 'ap\_mac' = x

I'm wondering if it is possible to use the IF state in a Current node to do the same? I can't work out the syntax to do it - if it is

[Next page](https://discourse.nodered.org/t/using-a-switch-node-with-jsonata/4867.md?page=2)
