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:


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

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
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.