Join/Concatenate Messages into 1 Object

This is probably trivial to someone but I'm struggling to get this right.

What I am trying to achieve:

image

What I am getting:

image

Goal is to have all the key/values in one object. I hope this terminology is correct. Please correct if not for my education.

Flow example:

[{"id":"8d949bac.d7c2c","type":"debug","z":"f6f2187d.f17ca8","name":"Incorrect","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":1260,"wires":[]},{"id":"1d86e5b3.84f24a","type":"inject","z":"f6f2187d.f17ca8","name":"Message 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"Value_A\" : \"A\" , \"Value_B\" : \"B\" }","payloadType":"json","x":220,"y":1220,"wires":[["d01fbcf6.026bf"]]},{"id":"d45c77e3.791cc8","type":"inject","z":"f6f2187d.f17ca8","name":"Message 2","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"Value_C\" : \"C\" }","payloadType":"json","x":220,"y":1260,"wires":[["d01fbcf6.026bf"]]},{"id":"d01fbcf6.026bf","type":"join","z":"f6f2187d.f17ca8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":390,"y":1260,"wires":[["8d949bac.d7c2c"]]},{"id":"12a7c354.98d85d","type":"debug","z":"f6f2187d.f17ca8","name":"Correct","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":1300,"wires":[]},{"id":"7e223754.7833b8","type":"inject","z":"f6f2187d.f17ca8","name":"Message 3","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"Value_A\" : \"A\" , \"Value_B\" : \"B\" , \"Value_C\" : \"C\" }","payloadType":"json","x":220,"y":1300,"wires":[["12a7c354.98d85d"]]}]

I have read here...
https://cookbook.nodered.org/basic/join-streams

And here...

Can't seem get this right. Any assistance is appreciated.

TIA

Use a topic for your two messages and then merge their payload with the Join node (based on their topics)
afterwards use a Function to restructure that msg to the final result.

I tried a few combinations with the Join node .. the above is what worked for me

[{"id":"8d949bac.d7c2c","type":"debug","z":"54efb553244c241f","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":980,"wires":[]},{"id":"1d86e5b3.84f24a","type":"inject","z":"54efb553244c241f","name":"msg1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"msg1","payload":"{ \"Value_A\" : \"A\" , \"Value_B\" : \"B\" }","payloadType":"json","x":330,"y":940,"wires":[["d01fbcf6.026bf"]]},{"id":"d45c77e3.791cc8","type":"inject","z":"54efb553244c241f","name":"msg2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"msg2","payload":"{ \"Value_C\" : \"C\" }","payloadType":"json","x":330,"y":1020,"wires":[["d01fbcf6.026bf"]]},{"id":"d01fbcf6.026bf","type":"join","z":"54efb553244c241f","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":510,"y":980,"wires":[["3f4585a14449f712","89d6da40b9d3e64d"]]},{"id":"3f4585a14449f712","type":"function","z":"54efb553244c241f","name":"merge","func":"msg.payload = {...msg.payload.msg1, ...msg.payload.msg2}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":980,"wires":[["8d949bac.d7c2c"]]},{"id":"89d6da40b9d3e64d","type":"debug","z":"54efb553244c241f","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":900,"wires":[]}]
1 Like

Figured out the settings of the Join node without the use of Topics or a function node
its merged Object and message parts 3 in this case

Example :

[{"id":"1d86e5b3.84f24a","type":"inject","z":"54efb553244c241f","name":"msg1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"Value_A\" : \"A\" , \"Value_B\" : \"B\" }","payloadType":"json","x":330,"y":940,"wires":[["d01fbcf6.026bf"]]},{"id":"d45c77e3.791cc8","type":"inject","z":"54efb553244c241f","name":"msg2","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"Value_C\" : \"C\" }","payloadType":"json","x":330,"y":1020,"wires":[["d01fbcf6.026bf"]]},{"id":"d01fbcf6.026bf","type":"join","z":"54efb553244c241f","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":510,"y":980,"wires":[["89d6da40b9d3e64d"]]},{"id":"89d6da40b9d3e64d","type":"debug","z":"54efb553244c241f","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":980,"wires":[]}]

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