# Object element naming based on another

**URL:** https://discourse.nodered.org/t/object-element-naming-based-on-another/33032
**Category:** General
**Created:** [18 September 2020 10:02 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032 "2020-09-18T10:02:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![FredMA](https://avatars.discourse-cdn.com/v4/letter/f/ed8c4c/32.png) [@FredMA](https://discourse.nodered.org/u/FredMA)
#### Post date: [18 September 2020 10:02 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032/1 "2020-09-18T10:02:47Z")

</div>

Hi,  
Sorry for the basic question, new to node-red and all that.  
I'm trying to add an element in a JSON object with a function node and the name is conditional to CSV data input ID column.

The setting is that I have some RF tags transmitting ID and temperature and I'd like to assign name depending on who is wearing the tag. Sorry again for this probably simple problem.

Input to function node:  
{"ID":"TAG+1 010","temp":27.1}

Function node:

var name = null;  
if (msg.ID == "TAG+1 010"){  
name = "Alfred";  
} else if (msg.ID == "TAG+1 073"){  
name = "Cathrine";  
}

msg.payload["Person"] = name

return msg;

From that I just get:

{"ID":"TAG+1 010","temp":27.1,"Person":null}

Thanks for any help with this problem!

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 September 2020 10:09 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032/2 "2020-09-18T10:09:31Z")

</div>

Hi @FredMA - welcome to the forum.

It looks like the data you are passing into the Function node is inside the `payload` property. So where you have `msg.ID` in your two `if` statements, I think you want `msg.payload.ID`.

---

<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: [18 September 2020 10:18 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032/3 "2020-09-18T10:18:03Z")

</div>

> [@FredMA](#):
>
> I'm trying to add an element in a JSON object

In fact it is a javascript object, not a JSON object. JSON is always a string. It may not seem that important, but using the wrong name can cause confusion.

---

<div class="post-metadata">

### Author: ![FredMA](https://avatars.discourse-cdn.com/v4/letter/f/ed8c4c/32.png) [@FredMA](https://discourse.nodered.org/u/FredMA)
#### Post date: [18 September 2020 11:31 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032/4 "2020-09-18T11:31:14Z")

</div>

That worked, naturally! Thanks for indulging a beginner!

---

<div class="post-metadata">

### Author: ![FredMA](https://avatars.discourse-cdn.com/v4/letter/f/ed8c4c/32.png) [@FredMA](https://discourse.nodered.org/u/FredMA)
#### Post date: [18 September 2020 11:31 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032/5 "2020-09-18T11:31:56Z")

</div>

Noted! Thanks!

---

<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: [2 October 2020 11:32 UTC](https://discourse.nodered.org/t/object-element-naming-based-on-another/33032/6 "2020-10-02T11:32:17Z")

</div>

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