From array to string with join

Hello all,
I am trying a very basic operation of turning an array to a string with join, but somehow I cannot make it.

This is how my message with the array look like:

Then I use a simple join node, set to string, to join the msg.payload (sorry for the German):

Aand this is what I get:

I expected a string with the elements ("bergen"; "nikolaus"; etc).
Is this not possible with the join node? Or has my array somehow a special structure somewhere??
I would like to do it without a function node if possible.
Thanks already for the help!

The join node expects a msg that is part of a collection of messages (the documentation describes what it expects as input).

If you first use a split node before going into the join node, it should work.

If you did split it you would have to move payload.suchen to payload for the join or state join payload.suchen.

You can also mess with msg.parts to split and join auto. Which means you do not have to add a count or send msg.complete.

Or you could use JSONata or Javascript to join.
e.g.

[{"id":"3332370c86e21b67","type":"inject","z":"d58a0e9fb6feb9d6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"suchen\":\"test\"},{\"suchen\":\"test2\"}]","payloadType":"json","x":170,"y":120,"wires":[["cbf08cf1c66cdd2c","5b26264edc9be773"]]},{"id":"cbf08cf1c66cdd2c","type":"split","z":"d58a0e9fb6feb9d6","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":330,"y":120,"wires":[["de616192c56f1418","fd50e927d69637d8"]]},{"id":"5b26264edc9be773","type":"change","z":"d58a0e9fb6feb9d6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$join($$.payload.suchen, \";\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":240,"wires":[["74032093f9e9f4e7"]]},{"id":"de616192c56f1418","type":"change","z":"d58a0e9fb6feb9d6","name":"","rules":[{"t":"move","p":"payload.suchen","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"parts.type","pt":"msg","to":"string","tot":"str"},{"t":"set","p":"parts.ch","pt":"msg","to":";","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":180,"wires":[["c26e2c2b758b6426"]]},{"id":"fd50e927d69637d8","type":"join","z":"d58a0e9fb6feb9d6","name":"","mode":"custom","build":"string","property":"payload.suchen","propertyType":"msg","key":"topic","joiner":":","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":120,"wires":[["014583d65b87c54f"]]},{"id":"74032093f9e9f4e7","type":"debug","z":"d58a0e9fb6feb9d6","name":"debug 313","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":240,"wires":[]},{"id":"c26e2c2b758b6426","type":"join","z":"d58a0e9fb6feb9d6","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":590,"y":180,"wires":[["251c9b8b9dbb4ba4"]]},{"id":"014583d65b87c54f","type":"debug","z":"d58a0e9fb6feb9d6","name":"debug 315","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":120,"wires":[]},{"id":"251c9b8b9dbb4ba4","type":"debug","z":"d58a0e9fb6feb9d6","name":"debug 314","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":180,"wires":[]}]

Hello bakman2,
When using the split node the structure of the array is exactly the same. I tried it as well, and could see in the msg.parts the count, length and index of each message. Nevertheless, the message after the join was exactly like the one that I have shown here. If I set the join to array, then the new message is exactly the same as the original one in my first screenshot.
So to summarize, the split worked as designed, but did not help me to get the string as I need it.

I tried moving the payload.suchen, but I think in this case I also have to indicate which element right? So i would have to explicitly give the split node to move payload.suchen[0] to payload[0]?
This is not possible, as my array may increase in size and I will not know the last element?

No, did you look at my examples. You do it after the split, when each payload is an object.

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