# Set Object name from msg.topic?

**URL:** <https://discourse.nodered.org/t/set-object-name-from-msg-topic/31987>\
**Category:** General\
**Created:** [25 August 2020 13:00 UTC](https://discourse.nodered.org/t/set-object-name-from-msg-topic/31987 "2020-08-25T13:00:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brew](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brew/32/19776_2.png) [@Brew](https://discourse.nodered.org/u/Brew)\
**Post date:** [25 August 2020 13:00 UTC](https://discourse.nodered.org/t/set-object-name-from-msg-topic/31987/1 "2020-08-25T13:00:38Z")

</div>

Hi All, I'm banging my head with this and I'm sure the answer is obvious but I can't find the search term or work it out.

I'm pinging a series of devices with the ping node I want to create a message object that contains device:ping\_value

All the info is in there as msg.topic contains the device name  
And msg.payload contains the ping value

sadly this doesn't work.

```auto
msg.payload = {msg.topic:msg.payload}; 
return msg;

```

so how can I combine the two?

At present I'm making a bunch of function nodes that are manually setting the object name.

```auto
msg.payload = {
    Rpi2White:msg.payload
};
return msg;

```

 ![Screenshot 2020-08-25 at 13.57.59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b71f0240e9c180767215b72e988d4d797108b937.png)

---

<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:** [25 August 2020 13:13 UTC](https://discourse.nodered.org/t/set-object-name-from-msg-topic/31987/2 "2020-08-25T13:13:37Z")

</div>

Something like

```auto
let value = msg.payload
msg.payload = {}
msg.payload[msg.topic] = value

```

---

<div class="post-metadata">

**Author:** ![Brew](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brew/32/19776_2.png) [@Brew](https://discourse.nodered.org/u/Brew)\
**Post date:** [25 August 2020 13:29 UTC](https://discourse.nodered.org/t/set-object-name-from-msg-topic/31987/3 "2020-08-25T13:29:29Z")

</div>

Perfect thank you so very much.

---

<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:** [8 September 2020 13:29 UTC](https://discourse.nodered.org/t/set-object-name-from-msg-topic/31987/4 "2020-09-08T13:29:38Z")

</div>

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