Moving whole object one level down

Hallo,

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 try.jsonata.org it works perfectly, see https://try.jsonata.org/-EXMYr4nV

If I try it with change node
grafik
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
}
1 Like

Works. Thank you very much.

The question still is. Why does it work on try.jsonata.org, 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.

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