# Little stuck with JSON syntax using node.send in a function node

**URL:** <https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304>\
**Category:** General\
**Created:** [26 November 2022 22:28 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304 "2022-11-26T22:28:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![philosoma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/philosoma/32/45241_2.png) [@philosoma](https://discourse.nodered.org/u/philosoma)\
**Post date:** [26 November 2022 22:28 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/1 "2022-11-26T22:28:57Z")

</div>

From a ZigBee extension lead I get states for each of the sockets like msg.payload.state\_l1. I'm using node.send to filter out the rest so the button node will work.

```auto
msg.payload.state_l1 = "ON";
node.send([{payload:msg.payload.state_l1}, null, null]);

```

This works, but it outputs as msg.payload and I can't get the JSON correct to output msg.payload.state\_l1. So I want to change the payload: bit to something like payload.state\_l1: but so it works.

Any help much appreciated!

---

<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:** [26 November 2022 22:33 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/2 "2022-11-26T22:33:55Z")

</div>

You may need to use the `JSON` node.

Not sure, but it may help.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 November 2022 22:57 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/3 "2022-11-26T22:57:17Z")

</div>

Maybe  
node.send([{payload:msg.payload},null,null]);

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [27 November 2022 10:12 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/5 "2022-11-27T10:12:40Z")

</div>

> [@philosoma](#):
>
> `node.send([{payload:msg.payload.state_l1}, null, null]);`

Not exactly answering your question, but....  
Wouldn't this be an opportunity to simplify the format of the zigbee msg, and instead of passing another JSON object (where you would then need to extract the value again later), move the value to `payload`, and add a msg.topic such as 'zigbee3' or something clearer like 'lounge\_lighting', so the it can be easily identified as it runs through the flow.

`node.send([{ payload: msg.payload.state_l1, topic:'zigbee3' }, null, null]);`

Output -

`{"payload":56,"topic":"zigbee3"}`

---

<div class="post-metadata">

**Author:** ![philosoma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/philosoma/32/45241_2.png) [@philosoma](https://discourse.nodered.org/u/philosoma)\
**Post date:** [27 November 2022 12:10 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/6 "2022-11-27T12:10:11Z")

</div>

Hi, thanks for the replies!

This does work for the switch on the dashboard but it doesn't update if the device is physically pressed.

The switch node is set to JSON with {"state\_l1":"ON"} and {"state\_l1":"OFF"} for on and off, and it seems like it has to only have that message to trigger. If state\_l2 and l3 is present in the object it doesn't work.

Took me awhile to figure this out as the zigbee2mqtt sends out a single state message if done from Node RED but not if the button physically pressed or triggered from another device, so it worked some of the time.

I've fixed it with a change node to move payload to payload.state\_l1 for each of the outputs.

---

<div class="post-metadata">

**Author:** ![philosoma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/philosoma/32/45241_2.png) [@philosoma](https://discourse.nodered.org/u/philosoma)\
**Post date:** [27 November 2022 12:16 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/7 "2022-11-27T12:16:26Z")

</div>

Thanks for the reply.

I was using the original message as I had to send it back to a MQTT node the same way for it to work. Just wish the dashboard stuff allowed me use something other than payload.

---

<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:** [27 November 2022 13:35 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/8 "2022-11-27T13:35:45Z")

</div>

> [@philosoma](#):
>
> Just wish the dashboard stuff allowed me use something other than payload.

Most ui nodes do allow that. You can put in the Value Format field something like `{{msg.payload.state_l1}}`

---

<div class="post-metadata">

**Author:** ![philosoma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/philosoma/32/45241_2.png) [@philosoma](https://discourse.nodered.org/u/philosoma)\
**Post date:** [27 November 2022 17:32 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/9 "2022-11-27T17:32:28Z")

</div>

Hey Colin.

I've used this to display values before, but can I use this in the on/off fields in a switch node?

Thanks!

---

<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:** [27 November 2022 17:57 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/10 "2022-11-27T17:57:49Z")

</div>

> [@philosoma](#):
>
> can I use this in the on/off fields in a switch node

No, I don't believe so.

---

<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:** [26 January 2023 17:58 UTC](https://discourse.nodered.org/t/little-stuck-with-json-syntax-using-node-send-in-a-function-node/71304/11 "2023-01-26T17:58:34Z")

</div>

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