Moving whole object one level down


I want to move the whole message one level down. So everything what is in the message should go to payload.
I try with

    "payload" : $

On it works perfectly, see

If I try it with change node
I get an error "[Circular ~]"

Heres my flow

[{"id":"38d4e33d.46e48c","type":"inject","z":"f4567829.04c76","name":"","props":[{"p":"object1","v":"{\"test\":\"test\"}","vt":"json"},{"p":"object2","v":"{ \"test\" : \"test\" }","vt":"json"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"myPayload","payloadType":"str","x":280,"y":300,"wires":[["6935444e.d3cc8c"]]},{"id":"f0a773ee.417d58","type":"debug","z":"f4567829.04c76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":300,"wires":[ ]},{"id":"6935444e.d3cc8c","type":"change","z":"f4567829.04c76","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":300,"wires":[["f0a773ee.417d58"]]}]

Function node...

return { 
  payload : msg

Works. Thank you very much.

The question still is. Why does it work on, but not in Node-Red. Thats confusing.

I find JSONata confusing :smiley:

For me, the function node is much easier & is definitely faster & there are far more JS programmers than JSONata programmers around for when I get stuck.

But I it might be an issue - I dont know. Lets see if anyone else responds.

When you try it on the JSONata website, you start with object A, and you create a new object B that has its payload set to Object A.

In the Change node, you have Object A, and try to set A.payload to A - which creates a circular reference and will fail.

They are not the same operations.