# Combine payloads into 1 JSON object

**URL:** <https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744>\
**Category:** General\
**Tags:** function-node\
**Created:** [19 January 2024 23:25 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744 "2024-01-19T23:25:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garrian](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@Garrian](https://discourse.nodered.org/u/Garrian)\
**Post date:** [19 January 2024 23:25 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744/1 "2024-01-19T23:25:20Z")

</div>

Hi there,

I want to combine the different outputs from OPCUA client into 1 JSON object, to be published to MQTT.

This is how the flow looks like:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c1418143c51f531b5472a718b9bc6490aa697d5e.png)

And the output from the client looks like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/304b0f24046400a95831941de7230c16ee088928.png)

So, my plan was to filter out the different messages by the topic, and combine the payload into 1 JSON object. The topic is the same as the opcua-string.

Any ideas for how this can be done? Hopefully within one function node.

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 January 2024 23:34 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744/2 "2024-01-19T23:34:47Z")

</div>

> [@Garrian](#):
>
> So, my plan was to filter out the different messages by the topic, and combine the payload into 1 JSON object. The topic is the same as the opcua-string.
> 
> Any ideas for how this can be done? Hopefully within one function node.

That's what the join node is for.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efd06666563b24f612723b3647345cfcc44b511b.png)

---

<div class="post-metadata">

**Author:** ![Garrian](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@Garrian](https://discourse.nodered.org/u/Garrian)\
**Post date:** [19 January 2024 23:38 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744/3 "2024-01-19T23:38:56Z")

</div>

Wow, that was almost too perfect, thanks 🙂

Any easy way to remove this part of the string/name?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9964d6dbecaa0c4280c9af67593469ef1e76824.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 January 2024 23:44 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744/4 "2024-01-19T23:44:13Z")

</div>

Function node before the join...

```auto
msg.topic = msg.topic.replace('ns=4;s=|var|HetlelidAuto.Application.0PCUA.','')
return msg

```

(Likely a typo in what I wrote but you did post a picture instead of text! ,🤷‍♂️

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [20 January 2024 02:40 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744/5 "2024-01-20T02:40:07Z")

</div>

@Steve-Mcl answer is correct short, simple and easy

> [@Garrian](#):
>
> Any easy way to remove this part of the string/name?

I would use [https://flows.nodered.org/node/node-red-contrib-string](https://flows.nodered.org/node/node-red-contrib-string) for this if there is any chance that,

```auto
ns=4;s=|var|HetlelidAuto.Application.0PCUA.

```

could change in the future.

---

<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:** [20 March 2024 02:40 UTC](https://discourse.nodered.org/t/combine-payloads-into-1-json-object/84744/6 "2024-03-20T02:40:13Z")

</div>

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