# Manipulating Message Contents - A nudge in the right direction needed

**URL:** <https://discourse.nodered.org/t/manipulating-message-contents-a-nudge-in-the-right-direction-needed/58887>\
**Category:** General\
**Created:** [23 February 2022 15:34 UTC](https://discourse.nodered.org/t/manipulating-message-contents-a-nudge-in-the-right-direction-needed/58887 "2022-02-23T15:34:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [23 February 2022 15:34 UTC](https://discourse.nodered.org/t/manipulating-message-contents-a-nudge-in-the-right-direction-needed/58887/1 "2022-02-23T15:34:59Z")

</div>

Hi Oracles!!

I have a problem with the syntax needed to manipulate message contents...

Coming into a function node, I have a msg.payload of True or False, and a message topic-ie "powerOn"

I need to manipulate this info to give me an output of: "msg.payload.powerOn" where its value would be the boolean as received... The "powerOn" suffix is a variable depending on what is selected elsewhere on a dash....

Any help would be immensely appreciated!

TIA  
Ed

Edit: For sake of clarity-

```auto
mysuffix = msg.topic
Data = msg.payload
msg.payload.(whatever is stored in mysuffix) = Data
return msg;

```

---

<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:** [23 February 2022 15:47 UTC](https://discourse.nodered.org/t/manipulating-message-contents-a-nudge-in-the-right-direction-needed/58887/2 "2022-02-23T15:47:28Z")

</div>

```auto
mysuffix = msg.topic
Data = msg.payload
msg.payload = {} // initialise msg.payload to an object
msg.payload[mysuffix] = Data
return msg

```

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [23 February 2022 15:55 UTC](https://discourse.nodered.org/t/manipulating-message-contents-a-nudge-in-the-right-direction-needed/58887/4 "2022-02-23T15:55:59Z")

</div>

Spot On!!!

Thanks Heapzzzzz!!!

(One fullstop in the wrong place... I had: msg.payload.[mysuffix] = Data .... amongst about 30 other ways to screw it up)

Ed

---

<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:** [9 March 2022 15:56 UTC](https://discourse.nodered.org/t/manipulating-message-contents-a-nudge-in-the-right-direction-needed/58887/5 "2022-03-09T15:56:47Z")

</div>

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