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

**URL:** <https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314>\
**Category:** General\
**Created:** [17 April 2021 08:53 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314 "2021-04-17T08:53:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozett](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ozett/32/28862_2.png) [@ozett](https://discourse.nodered.org/u/ozett)\
**Post date:** [17 April 2021 08:53 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/1 "2021-04-17T08:53:46Z")

</div>

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) ?

 ![jsonata1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d348bf3cff7f7b88dfd559a3b8e3d6851ae36b7c.jpeg)

```auto
[{"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](https://it.knightnet.org.uk/kb/nr-qa/jsonata/) helped, but dont show more how/where to set jsonata onto node-red objets in change-node exacty, i guess

any hints appreciated

---

<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:** [17 April 2021 09:49 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/2 "2021-04-17T09:49:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ozett](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ozett/32/28862_2.png) [@ozett](https://discourse.nodered.org/u/ozett)\
**Post date:** [17 April 2021 15:09 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/3 "2021-04-17T15:09:30Z")

</div>

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?

---

<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:** [17 April 2021 15:29 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/4 "2021-04-17T15:29:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ozett](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ozett/32/28862_2.png) [@ozett](https://discourse.nodered.org/u/ozett)\
**Post date:** [17 April 2021 15:45 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/5 "2021-04-17T15:45:32Z")

</div>

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

---

<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:** [17 April 2021 16:50 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/6 "2021-04-17T16:50:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ozett](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ozett/32/28862_2.png) [@ozett](https://discourse.nodered.org/u/ozett)\
**Post date:** [17 April 2021 17:04 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/7 "2021-04-17T17:04:41Z")

</div>

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

---

<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:** [17 April 2021 17:28 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/8 "2021-04-17T17:28:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ozett](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ozett/32/28862_2.png) [@ozett](https://discourse.nodered.org/u/ozett)\
**Post date:** [17 April 2021 17:50 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/9 "2021-04-17T17:50:17Z")

</div>

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?](https://it.knightnet.org.uk/kb/nr-qa/jsonata/#convert-an-array-of-objects-into-an-object-of-objects)) visualisation and syntax for objects, arrays, properties.. and dont get it straigth right. as now...

---

<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 June 2021 17:51 UTC](https://discourse.nodered.org/t/jsonate-in-change-node-to-set-root-msg-possible/44314/10 "2021-06-16T17:51:11Z")

</div>

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