# Join/Concatenate Messages into 1 Object

**URL:** <https://discourse.nodered.org/t/join-concatenate-messages-into-1-object/58093>\
**Category:** General\
**Created:** [10 February 2022 17:46 UTC](https://discourse.nodered.org/t/join-concatenate-messages-into-1-object/58093 "2022-02-10T17:46:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DuncanCT](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duncanct/32/41639_2.png) [@DuncanCT](https://discourse.nodered.org/u/DuncanCT)\
**Post date:** [10 February 2022 17:46 UTC](https://discourse.nodered.org/t/join-concatenate-messages-into-1-object/58093/1 "2022-02-10T17:46:02Z")

</div>

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

What I am trying to achieve:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/5879cf4978ff411e0bce99bc88c1ef30e4b6dbe3.png)

What I am getting:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f42e7d4c25f30d80d219471a06e31e817d40fc07.png)

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:

```auto
[{"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](https://cookbook.nodered.org/basic/join-streams)

And here...

> **[JavaScript Array concat() Method](https://www.w3schools.com/jsref/jsref_concat_array.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

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

TIA

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 February 2022 18:40 UTC](https://discourse.nodered.org/t/join-concatenate-messages-into-1-object/58093/2 "2022-02-10T18:40:40Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 February 2022 22:54 UTC](https://discourse.nodered.org/t/join-concatenate-messages-into-1-object/58093/3 "2022-02-10T22:54:14Z")

</div>

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 :**

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 February 2022 22:54 UTC](https://discourse.nodered.org/t/join-concatenate-messages-into-1-object/58093/4 "2022-02-24T22:54:34Z")

</div>

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