# How can I change property name in object array?

**URL:** <https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398>\
**Category:** General\
**Created:** [2 January 2021 14:38 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398 "2021-01-02T14:38:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgalilio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kgalilio/32/31512_2.png) [@kgalilio](https://discourse.nodered.org/u/kgalilio)\
**Post date:** [2 January 2021 14:38 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/1 "2021-01-02T14:38:24Z")

</div>

I need to change the property name from msg.annotations. **class** to msg.annotations. **label** in the following object:

```auto
{"_msgid":"ee4eb36c.5aa95","classes":[{"bbox":[18.903613090515137,158.94189834594727,47.1713924407959,77.05244064331055],"class":"person","score":0.5755487680435181},{"bbox":[258.31018447875977,190.7409954071045,46.54521942138672,44.46455955505371],"class":"person","score":0.5297119617462158},{"bbox":[28.069658279418945,1.2499237060546875,285.34571647644043,237.3603343963623],"class":"person","score":0.5256894826889038}],"annotations":[{"bbox":[18.903613090515137,158.94189834594727,47.1713924407959,77.05244064331055],"class":"person","score":0.5755487680435181},{"bbox":[258.31018447875977,190.7409954071045,46.54521942138672,44.46455955505371],"class":"person","score":0.5297119617462158},{"bbox":[28.069658279418945,1.2499237060546875,285.34571647644043,237.3603343963623],"class":"person","score":0.5256894826889038}]}

```

I've tried using the Edit Change Node with Set, Change, Move, but I can't seem to get it right.  
Any help would be highly appreciated.

---

<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:** [2 January 2021 15:11 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/2 "2021-01-02T15:11:12Z")

</div>

You can use a Change node to Move msg.annotations.class To msg.annotations.label.

---

<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:** [2 January 2021 15:18 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/3 "2021-01-02T15:18:44Z")

</div>

There are multiple  
msg.annotations[0].class  
msg.annotations[1].class  
msg.annotations[2].class

so you would need to write a function if there will be a variable numbers, or use a jsonata expression.

---

<div class="post-metadata">

**Author:** ![kgalilio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kgalilio/32/31512_2.png) [@kgalilio](https://discourse.nodered.org/u/kgalilio)\
**Post date:** [2 January 2021 15:21 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/4 "2021-01-02T15:21:02Z")

</div>

Thanks @Colin. I tried this earlier, but it didn't work.

---

<div class="post-metadata">

**Author:** ![kgalilio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kgalilio/32/31512_2.png) [@kgalilio](https://discourse.nodered.org/u/kgalilio)\
**Post date:** [2 January 2021 15:24 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/5 "2021-01-02T15:24:19Z")

</div>

Thanks @E1cid. I tried Jsonata, but the problem is the array. If it was a single object, it would have been easier; but I have no clue on how to apply this in an array.  
Using (msg.annotations.class) does return all the class elements. But I need to change the name of the property, rather than returning its value.

---

<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:** [2 January 2021 15:25 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/6 "2021-01-02T15:25:56Z")

</div>

Use [array map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) function in a function node.

---

<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:** [2 January 2021 15:35 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/7 "2021-01-02T15:35:28Z")

</div>

try j expression  
set msg.annotations  
to  
`annotations ~> |[*]|{'label': class}, 'class'|`

---

<div class="post-metadata">

**Author:** ![kgalilio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kgalilio/32/31512_2.png) [@kgalilio](https://discourse.nodered.org/u/kgalilio)\
**Post date:** [2 January 2021 15:39 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/8 "2021-01-02T15:39:47Z")

</div>

Perfect! Thanks a million.

---

<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:** [16 January 2021 15:39 UTC](https://discourse.nodered.org/t/how-can-i-change-property-name-in-object-array/38398/9 "2021-01-16T15:39:47Z")

</div>

Closed on 16 January 2021 15:39 UTC

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