# How to add an object to the Node-RED msg.payload

**URL:** <https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111>\
**Category:** General\
**Created:** [13 April 2021 14:26 UTC](https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111 "2021-04-13T14:26:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vongomben](https://avatars.discourse-cdn.com/v4/letter/v/a4c791/32.png) [@vongomben](https://discourse.nodered.org/u/vongomben)\
**Post date:** [13 April 2021 14:26 UTC](https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111/1 "2021-04-13T14:26:09Z")

</div>

Hi.  
I'm failing in adding elements to the payload object, simply because the payload iself it not declared at the beginning of the flow as object.  
I've found many other users facing this problem, and while I understood the problem itself, is totally unclear on how to solve it.

[This Stackoverflow](https://stackoverflow.com/questions/52015228/how-to-add-an-object-to-the-node-red-msg-payload) is the closest solution I've found, but failing to implement, while [previous threads](https://discourse.nodered.org/t/building-a-3-element-array-from-form-and-dropdown-nodes-to-send-on-button-click/30385/12) on the forum weren't fully understandable (at least to me)

I have documented my problem here, is anybody can give a look I'll be super grateful.  
Thanks in advance.

```auto
[{"id":"bf60b8.b136b748","type":"http request","z":"fab6f208.77334","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://www.freeforexapi.com/api/live?pairs={{payload.from}}{{payload.to}}","tls":"","persist":false,"proxy":"","authType":"","x":650,"y":560,"wires":[["f0831588.228b58"]]},{"id":"e4cab682.a14598","type":"ui_text_input","z":"fab6f208.77334","name":"","label":"","tooltip":"","group":"b750e8e.87cde18","order":3,"width":"4","height":"1","passthru":true,"mode":"number","delay":300,"topic":"payload.value","x":130,"y":180,"wires":[["a1973af7.20f3f"]]},{"id":"c60c34d1.257e","type":"ui_dropdown","z":"fab6f208.77334","name":"","label":"from","tooltip":"","place":"Select option","group":"b750e8e.87cde18","order":1,"width":"4","height":"1","passthru":true,"multiple":false,"options":[{"label":"EUR","value":"EUR","type":"str"},{"label":"USD","value":"USD","type":"str"},{"label":"GBP","value":"GBP","type":"str"}],"payload":"","topic":"from","x":150,"y":120,"wires":[["40f2b184.591cb"]]},{"id":"15137eaa.baaab9","type":"ui_dropdown","z":"fab6f208.77334","name":"","label":"to","tooltip":"","place":"Select option","group":"b750e8e.87cde18","order":1,"width":"4","height":"1","passthru":true,"multiple":false,"options":[{"label":"EUR","value":"EUR","type":"str"},{"label":"USD","value":"USD","type":"str"},{"label":"GBP","value":"GBP","type":"str"}],"payload":"","topic":"to","x":150,"y":240,"wires":[["81cca0e3.4dd0f8"]]},{"id":"628853bf.66bfd4","type":"ui_button","z":"fab6f208.77334","name":"","group":"b750e8e.87cde18","order":0,"width":"1","height":"1","passthru":false,"label":"covert","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"payload","x":110,"y":420,"wires":[["90dad6c6.cc6f08"]]},{"id":"f0831588.228b58","type":"debug","z":"fab6f208.77334","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":560,"wires":[]},{"id":"81cca0e3.4dd0f8","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"to","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":240,"wires":[[]]},{"id":"a1973af7.20f3f","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"value","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":180,"wires":[[]]},{"id":"40f2b184.591cb","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"from","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":120,"wires":[[]]},{"id":"24e9e8eb.081cc8","type":"debug","z":"fab6f208.77334","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":400,"wires":[]},{"id":"93e6edc4.7fc7","type":"inject","z":"fab6f208.77334","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":460,"wires":[["90dad6c6.cc6f08"]]},{"id":"90dad6c6.cc6f08","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"payload.to","pt":"msg","to":"to","tot":"flow"},{"t":"set","p":"payload.from","pt":"msg","to":"from","tot":"flow"},{"t":"set","p":"payload.value","pt":"msg","to":"value","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":440,"wires":[["24e9e8eb.081cc8"]]},{"id":"79281847.c5e318","type":"inject","z":"fab6f208.77334","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":630,"y":240,"wires":[["6f713608.c86e28"]]},{"id":"6f713608.c86e28","type":"debug","z":"fab6f208.77334","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":240,"wires":[]},{"id":"3d4263c2.ced29c","type":"comment","z":"fab6f208.77334","name":"Dropdown Payloads that are moved to the Flow Context","info":"","x":240,"y":60,"wires":[]},{"id":"dc148259.1f642","type":"comment","z":"fab6f208.77334","name":"Setting the Payload as Object when Triggering the flow","info":"","x":740,"y":180,"wires":[]},{"id":"e0287405.264198","type":"comment","z":"fab6f208.77334","name":"Trying to see all 3 different dropdown payload in the same object","info":"","x":270,"y":360,"wires":[]},{"id":"a3a31007.ff02f","type":"comment","z":"fab6f208.77334","name":"expecting two payload values to populate this http request","info":"","x":750,"y":500,"wires":[]},{"id":"b750e8e.87cde18","type":"ui_group","name":"cambia-valuta","tab":"414a2b76.3ce37c","order":1,"disp":true,"width":"6","collapse":false},{"id":"414a2b76.3ce37c","type":"ui_tab","name":"cambia-valuta","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [13 April 2021 14:46 UTC](https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111/2 "2021-04-13T14:46:10Z")

</div>

You don't appear to have implemented the suggestion in the stackoverflow link, which is to set msg.payload to an empty object first. Like this

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

---

<div class="post-metadata">

**Author:** ![vongomben](https://avatars.discourse-cdn.com/v4/letter/v/a4c791/32.png) [@vongomben](https://discourse.nodered.org/u/vongomben)\
**Post date:** [14 April 2021 07:19 UTC](https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111/3 "2021-04-14T07:19:57Z")

</div>

> [@Colin](#):
>
> You don't appear to have implemented the suggestion in the stackoverflow link, which is to set msg.payload to an empty object first. Like this

Thanks Colin.  
I thoughts the inject node that was creating an empty object at the very beginning of the flow was enough!

Now it works fine

---

<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:** [14 April 2021 08:13 UTC](https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111/4 "2021-04-14T08:13:48Z")

</div>

> [@vongomben](#):
>
> I thoughts the inject node that was creating an empty object at the very beginning of the flow was enough!

I don't see an inject node creating an empty object in the flow you posted. In fact you could instead solve the problem by making the `covert` button send an empty object, but it is probably clearer to put it in the Change node.

---

<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:** [28 April 2021 08:14 UTC](https://discourse.nodered.org/t/how-to-add-an-object-to-the-node-red-msg-payload/44111/5 "2021-04-28T08:14:36Z")

</div>

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