Allow target to be also a jsonata expression

Sometimes it would be handy to dynamically define not only the source but also the target field in a change node.

So the "set" option should be extended with the jsonata expression.

So what happens if the JSONata expression returns [1,2,3] - what should we set?

It would be logical that the expression has to evaluate to a valid field (existing or new in the msg - maybe also context).
So in your example, i guess nothing would be set.

Can you give an example of what the expression could be? How does it return something that identifies the field of the message to set, rather than the value of that field?

In the source field i can enter something like this:


which returns a field in payload[1], defined by the string in .p1 (like "")


I also need to same thing. Being able to dynamically create/set properties from a change node.

I could be a Jsonata expression in the target properties, or to be able to access properties in a Javascript way

Boolean true

As msg.topic is a a string for the target mode that would eventually means

Thank you

This would be very valuable. I am writing a flow that changes the brightness or colour of a device depending on other inputs. In order to keep my code compact and general I'd like to re-use most of the flow and send a different message to the device depending on whether I am changing colour or brightness.

Unfortunately, the device doesn't look in the payload but in discrete properties of the message. So if need to change the brightness I need to send a message that contains {brightness : 100} in the message object.

In other words I need

_msgid: xxxxxxxxx
topic: ""
payload: ""
brightness: 100

However, the Change node will not let me programmatically choose whether to set a brightness property or a colour property in the top level message object. I can output {brightness : 100} or {colour : 100} to the payload property depending on a jsonata. I do that simply by setting the target to msg.payload.

But doesn't work if I leave the target blank with the aim of sending that object to the top level. The flow fails - presumably becasue it would replace the msg object and so delete the topic and _msgid.

I think this is the use case that people are referring to above.

Can we adapt the change node so that an object can be added to the top level msg object or so that the target property of the Change node can also be the result of a jsonata expression?