Setting payload to JSONata expression isnt working!

PFB the flow -

[{"id":"df540054.4bb3c","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"169841e2.bd633e","type":"inject","z":"df540054.4bb3c","name":"","topic":"","payload":"{\"payload\":[{\"FirstName\":\"Fred\",\"Surname\":\"Smith\",\"Age\":28,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 5441234\"},{\"type\":\"office\",\"number\":\"00 44 1962 001234\"},{\"type\":\"mobile\",\"number\":\"0044 7777-001234\"}]},{\"FirstName\":\"Jim\",\"Surname\":\"Stoppani\",\"Age\":25,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 9871234\"},{\"type\":\"office\",\"number\":\"00 44 1962 998765\"},{\"type\":\"mobile\",\"number\":\"0044 7777-098765\"}]}]}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":120,"wires":[["6269db8b.a87c14","e9acb6c8.8574a8"]]},{"id":"239084e8.6d41cc","type":"debug","z":"df540054.4bb3c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":530,"y":120,"wires":[]},{"id":"6269db8b.a87c14","type":"change","z":"df540054.4bb3c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload{\t   FirstName & ' ' & Surname : Phone{type:\t   $replace(number,/^(\\+|00)\\s*(\\d*)[\\s-]+(\\d*)[\\s-]+(\\d*)$/,'+$2 $3-$4')}\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":120,"wires":[["239084e8.6d41cc"]]},{"id":"e9acb6c8.8574a8","type":"debug","z":"df540054.4bb3c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":310,"y":220,"wires":[]}]

The debug node attached to the change node prints an empty node!!Could not understand why

Can somebody please advice

Thanks,
Albin

Take "payload" out of your inject (Inject JSON already puts your JSON into msg.payload. In effect your data was in msg.payload.payload & thus the JSONata didnt match)

[{"id":"4ca1f2af.b3877c","type":"inject","z":"d883943f.350f28","name":"","topic":"","payload":"[{\"FirstName\":\"Fred\",\"Surname\":\"Smith\",\"Age\":28,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 5441234\"},{\"type\":\"office\",\"number\":\"00 44 1962 001234\"},{\"type\":\"mobile\",\"number\":\"0044 7777-001234\"}]},{\"FirstName\":\"Jim\",\"Surname\":\"Stoppani\",\"Age\":25,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 9871234\"},{\"type\":\"office\",\"number\":\"00 44 1962 998765\"},{\"type\":\"mobile\",\"number\":\"0044 7777-098765\"}]}]","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":120,"wires":[["d8818ef4.046a9","4a5330fe.efa98","7ad4f4e0.3c2f4c"]]},{"id":"edce5ac5.ad5288","type":"debug","z":"d883943f.350f28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":530,"y":120,"wires":[]},{"id":"d8818ef4.046a9","type":"change","z":"d883943f.350f28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload{\t FirstName & ' ' & Surname : Phone{type:\t $replace(number,/^(\\+|00)\\s*(\\d*)[\\s-]+(\\d*)[\\s-]+(\\d*)$/,'+$2 $3-$4')}\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":120,"wires":[["edce5ac5.ad5288"]]},{"id":"4a5330fe.efa98","type":"debug","z":"d883943f.350f28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":310,"y":220,"wires":[]},{"id":"7ad4f4e0.3c2f4c","type":"debug","z":"d883943f.350f28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload{\t FirstName & ' ' & Surname : Phone{type:\t $replace(number,/^(\\+|00)\\s*(\\d*)[\\s-]+(\\d*)[\\s-]+(\\d*)$/,'+$2 $3-$4')}\t}","targetType":"jsonata","x":300,"y":160,"wires":[]}]

1 Like

@Steve-Mcl ..Thankyou..It worked