Jsonate in change-node to set root (msg.) possible?

fiddling for hours with jsonata, but not sure if its possible to create a whole new message?

how can i create a complete new .msg with jsonata (with additional new keys) ?

[{"id":"16a63eb5.2de521","type":"change","z":"1b0f8936.b72107","name":"","rules":[{"t":"set","p":"","pt":"msg","to":"{  \"topic\": topic,\t   \"payload\": {\"payload\": $, \"filekey\": \"33\"} ,\t   \"_msgid\": _msgid,\t   \"payload.filekey\" :\"nix\"\t   }\t   ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":120,"wires":[["8fc2fd32.39362"]]}]

this Using JSONata to transform msg data | Much Ado About IT helped, but dont show more how/where to set jsonata onto node-red objets in change-node exacty, i guess

any hints appreciated

Not possible in the change node as you can not set a blank msg, or address msg directly. Use a function node to affect msg directly

or address the individual properties separately, i.e set msg topic with one jsonata, msg.payload with another.

You can reference the complete msg using $merge([$$]) to avoid the circular reference.

oh, thanks for reply.
i thought there is maybe another way to create a complete new message?
maybe set one new property in the change-node with jsonata and adress all from root with $$. anbd create new/change properties? somehow?
maybe i just dont find the correct syntax for this, or realy it is not possible to create with this way a complete new message?

Do you want to generate an extra message (so you end up with two messages one after the other, the original and the new) or do you just want to change everything in the message to something else? If it is the latter then why?

i started to inject a complete newly created message.
the inject-node has some limitations, so i used it only as trigger and in the change-node i started fiddling wit jsonata to see if i can create a new message with new properties. an extra message does not hurt, but in short: i tried to create a complete new message with jsonata.
i still think if one can access $$ than somehow that should be possible. all recipes explain mostly the jsonata-inner functions and leave open how to set a new message up from the group and in the gui.
i know think i must use the change node because it has full access $$... but syntax is hard...

You have not explained why you want to generate a completely new message. Why can you not just change the message coming from the inject node to make it contain what you want?

i wanted to understand how to create a new message with jsonata to do it in the middle of my flows.
at least to add some new properties on certain flows...
i just started with the inject-node at the beginning of a testflow..
but i spent hours fiddling with jsonata syntax and had not even luck to create a new message in this simple test-flow... :crying_cat_face:

Oh I see, you specifically want to do it with jsonata rather than setting the individual properties in a change node, or creating a new message in a function node.

exactly. jsonata seems most powerful for a brilliant general solution, and all in the gui. seems for for small coding better to edit and at least better to debug there than mostly a function node. but every 2 weeks i must lookup the (complex?) visualisation and syntax for objects, arrays, properties.. and dont get it straigth right. as now...

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