How can I change property name in object array?

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

{"_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.

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

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.

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

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.

Use array map function in a function node.

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

1 Like

Perfect! Thanks a million.

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