# Separate the properties of a payload so i can send each individual values to another device

**URL:** https://discourse.nodered.org/t/separate-the-properties-of-a-payload-so-i-can-send-each-individual-values-to-another-device/31619
**Category:** General
**Created:** [16 August 2020 18:13 UTC](https://discourse.nodered.org/t/separate-the-properties-of-a-payload-so-i-can-send-each-individual-values-to-another-device/31619 "2020-08-16T18:13:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Maxking](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxking/32/27272_2.png) [@Maxking](https://discourse.nodered.org/u/Maxking)
#### Post date: [16 August 2020 18:13 UTC](https://discourse.nodered.org/t/separate-the-properties-of-a-payload-so-i-can-send-each-individual-values-to-another-device/31619/1 "2020-08-16T18:13:43Z")

</div>

Hi, I am a newbie here, sorry but we all have to start somewhere 🙂  
Anyway I am not a newbie with BMS (Building Management Systems) also know as BEMS (Building Energy Management Systems).  
The BMS control I use (Niagara Tridium N4 controller) has a MQTT pallet which works fine, no issues with sending or receiving MQTT data via my own server MQTT broker.

So my next step is to take a LoRaWan device back into the Tridium Niagara BMS controller.  
The LoRaWan device i am using takes MODBUS electric meter network signals and sends the meter values to my LoRaWAN gateway, then I currently send this data to [https://www.thethingsnetwork.org/](https://www.thethingsnetwork.org/) all fine, no issues.

Now to Node-Red, I take the information for this LoRaWAN device from [https://www.thethingsnetwork.org/](https://www.thethingsnetwork.org/) into Node-Red and the MQTT in node.

![mqtt_from_thethingsnetwork](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f8617c3e085a835c0ba2dc30fe02f0c22b96a50.jpeg)

I then create a basic flow which currently sends the data back to the Niagara Tridium N4 controller via MQTT out node, which sends fine and i have added a edit debug node.

Here is the debug data

```auto
{"topic":"modbuspowerbar_mcf88/devices/mcf88/up","payload":"{\"app_id\":\"modbuspowerbar_mcf88\",\"dev_id\":\"mcf88\",\"hardware_serial\":\"70B3D58FF1013E38\",\"port\":2,\"counter\":641,\"confirmed\":true,\"payload_raw\":\"CxQAEAABVAaAAasAXQW2AAAAFg==\",\"payload_fields\":{\"CPU_Temp\":34,\"MCB0_Mains\":1.664,\"MCB1_Freezers\":0.427,\"MCB2_Lights\":0.093,\"MCB3_Desk_Sockets_Aircon\":1.462,\"MCB4_Sockets\":0,\"MCB5_Spare\":0.022},\"metadata\":{\"time\":\"2020-08-16T18:04:14.238780126Z\",\"frequency\":868.5,\"modulation\":\"LORA\",\"data_rate\":\"SF7BW125\",\"airtime\":71936000,\"coding_rate\":\"4/5\",\"gateways\":[{\"gtw_id\":\"eui-60c5a8fffe766204\",\"timestamp\":1490131788,\"time\":\"\",\"channel\":7,\"rssi\":-43,\"snr\":8.5,\"rf_chain\":0,\"latitude\":51.88843,\"longitude\":-0.53416,\"altitude\":148}],\"latitude\":51.888424,\"longitude\":-0.53416693,\"altitude\":148,\"location_source\":\"registry\"}}","qos":0,"retain":false,"_msgid":"27e905e3.3f2b4a"}

```

Now what i would like to do is separate the payload\_fields, so i can send each individual field to the Niagara Tridium controller.

```auto
{\"CPU_Temp\":34,\"MCB0_Mains\":1.664,\"MCB1_Freezers\":0.427,\"MCB2_Lights\":0.093,\"MCB3_Desk_Sockets_Aircon\":1.462,\"MCB4_Sockets\":0,\"MCB5_Spare\":0.022}

```

I have looked through the forum, and see detailed information on the topic using a change node and a switch node, but not getting very far, so any help would be appreciated.

Below is the current input into the Tridium Niagara controller, which is a long string input.

 ![tridiumniagaracontroller](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/0845aec451e0910b1a9f3b3eb32295d5d7323471.jpeg)

Any ideas for the best way to extract the 7 fields in the payload ?

Thanks for reading.

---

<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: [16 August 2020 19:40 UTC](https://discourse.nodered.org/t/separate-the-properties-of-a-payload-so-i-can-send-each-individual-values-to-another-device/31619/2 "2020-08-16T19:40:22Z")

</div>

> [@Maxking](#):
>
> Here is the debug data
> 
> Now what i would like to do is separate the payload\_fields

So a small lesson on JS objects and their equivalent string representation (AKA JSON)...

_Your `payload` is a string/JSON (due to the `Output` setting on the MQTT node). You could attempt some complex splits and loops etc - but - as it is JSON (JavaScript Object Notation) - just let JS do its thing - turn that JSON back into a JS Object! (if you dont know what I mean, it'd be worth reading up - will help you greatly in node-red knowing the difference)_

So first off, change that MQTT IN to...

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

Now, you data will be an actual JS object (not a string / not JSON)...

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

And once its an object, you can simply "copy path" of any item in the object & use that in a change node (or whatever)...

 ![igkT318CBZ](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10a2bd9c1bde31eadf35fe52932044a66821decf.gif)

So, from that, you could generate new messages by using parallel change nodes...

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

ending up with this...

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

my demo flow...

```auto
[{"id":"635795b0.ebc5dc","type":"inject","z":"485b32f3.0bdfbc","name":"your MQTT IN data (faking it)","topic":"modbuspowerbar_mcf88/devices/mcf88/up","payload":"{\"app_id\":\"modbuspowerbar_mcf88\",\"dev_id\":\"mcf88\",\"hardware_serial\":\"70B3D58FF1013E38\",\"port\":2,\"counter\":641,\"confirmed\":true,\"payload_raw\":\"CxQAEAABVAaAAasAXQW2AAAAFg==\",\"payload_fields\":{\"CPU_Temp\":34,\"MCB0_Mains\":1.664,\"MCB1_Freezers\":0.427,\"MCB2_Lights\":0.093,\"MCB3_Desk_Sockets_Aircon\":1.462,\"MCB4_Sockets\":0,\"MCB5_Spare\":0.022},\"metadata\":{\"time\":\"2020-08-16T18:04:14.238780126Z\",\"frequency\":868.5,\"modulation\":\"LORA\",\"data_rate\":\"SF7BW125\",\"airtime\":71936000,\"coding_rate\":\"4/5\",\"gateways\":[{\"gtw_id\":\"eui-60c5a8fffe766204\",\"timestamp\":1490131788,\"time\":\"\",\"channel\":7,\"rssi\":-43,\"snr\":8.5,\"rf_chain\":0,\"latitude\":51.88843,\"longitude\":-0.53416,\"altitude\":148}],\"latitude\":51.888424,\"longitude\":-0.53416693,\"altitude\":148,\"location_source\":\"registry\"}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":140,"wires":[["cfe3cfe5.2fd24","d7eb57a2.3aa148","6d3aae76.88f9"]]},{"id":"362f42bb.e4a57e","type":"debug","z":"485b32f3.0bdfbc","name":"to MQTT Out node (or whatever)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":140,"wires":[]},{"id":"cfe3cfe5.2fd24","type":"change","z":"485b32f3.0bdfbc","name":"CPU_Temp","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload_fields.CPU_Temp","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"modbuspowerbar_mcf88/devices/mcf88/up/CPU_Temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":140,"wires":[["362f42bb.e4a57e"]]},{"id":"d7eb57a2.3aa148","type":"change","z":"485b32f3.0bdfbc","name":"MCB0_Mains","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload_fields.MCB0_Mains","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"modbuspowerbar_mcf88/devices/mcf88/up/MCB0_Mains","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":200,"wires":[["362f42bb.e4a57e"]]},{"id":"6d3aae76.88f9","type":"change","z":"485b32f3.0bdfbc","name":"MCB1_Freezers","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload_fields.MCB1_Freezers","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"modbuspowerbar_mcf88/devices/mcf88/up/MCB1_Freezers","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":260,"wires":[["362f42bb.e4a57e"]]}]

```

### EDIT...

I updated your threads topic as it was fairly inconsequential to do with what you were trying to achieve. In fact, I skipped over your question earlier as I had no clue what a "Niagara Tridium N4 controller" was & thought I couldn't help you (likely others did too). My point is, try to title your topics in relation to the goal or issue.

---

<div class="post-metadata">

### Author: ![Maxking](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxking/32/27272_2.png) [@Maxking](https://discourse.nodered.org/u/Maxking)
#### Post date: [16 August 2020 22:15 UTC](https://discourse.nodered.org/t/separate-the-properties-of-a-payload-so-i-can-send-each-individual-values-to-another-device/31619/3 "2020-08-16T22:15:39Z")

</div>

Thank you so much Steve, that worked great and the data is now exported to the Building Management system 😄

 ![Node-Red_to_BMS](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf3adf058fa25882e35e9d3817f4cd4c55f852f9.jpeg)

Thank you again for the quick answer back.

BMS Controller with MQTT inputs

 ![niagara_MQTT](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f5990d46915badce8600b9ac87f1eee163b69c6b.jpeg)

---

<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: [30 August 2020 22:15 UTC](https://discourse.nodered.org/t/separate-the-properties-of-a-payload-so-i-can-send-each-individual-values-to-another-device/31619/4 "2020-08-30T22:15:45Z")

</div>

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