# Multiple JSON message into one Function Node

**URL:** <https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524>\
**Category:** General\
**Tags:** function-node\
**Created:** [20 April 2022 07:39 UTC](https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524 "2022-04-20T07:39:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![antsals](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@antsals](https://discourse.nodered.org/u/antsals)\
**Post date:** [20 April 2022 07:39 UTC](https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524/1 "2022-04-20T07:39:43Z")

</div>

I'm sure this is really simple; I'm new to all this.

I had a string from a link node and I have re-defined as a JSON message through a function; with

msg.payload = {  
"OPC\_Tag": msg.topic,  
"Value": msg.payload  
}  
return msg;  
This is the output;

20/04/2022, 08:21:54node: e41071c52edf8130  
ns=3;s=OPC\_MAIN\_SUPPLY\_FLOW\_FT230 : msg.payload : Object  
object  
OPC\_Tag: "ns=3;s=OPC\_MAIN\_SUPPLY\_FLOW\_FT230"  
Value: "262.80"

I have multiple messages going into this node; and then into another function where I want to split the values out so I can do an if this equals that etc. So some how I need to have the message come into the second function node that is specific so I can tag the variables specific to the message.

Probably a bad explanation.....sure this simple.  
Cheers,  
Ant

---

<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:** [20 April 2022 09:11 UTC](https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524/2 "2022-04-20T09:11:20Z")

</div>

> [@antsals](#):
>
> I have re-defined as a JSON message through a function;  
> [...]  
> This is the output;  
> msg.payload : Object  
> object  
> OPC\_Tag: "ns=3;s=OPC\_MAIN\_SUPPLY\_FLOW\_FT230"  
> Value: "262.80"

That looks all ok, with the possible difficulty that your value is a string.

> [@antsals](#):
>
> I have multiple messages going into this node; and then into another function where I want to split the values out so I can do an if this equals that etc. So some how I need to have the message come into the second function node that is specific so I can tag the variables specific to the message.

I really can't understand what you are asking here. Is it that you want to compare data from one message with data from another?

Perhaps you can give us more examples of the data you have and the result you want to get?

---

<div class="post-metadata">

**Author:** ![antsals](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@antsals](https://discourse.nodered.org/u/antsals)\
**Post date:** [20 April 2022 18:56 UTC](https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524/3 "2022-04-20T18:56:26Z")

</div>

Apologies it is probably the worst explanation possiable.

So i have three nodes outputting numbers (msg.payload) each with a different topic; ie the name of the variable.

I want to bring them into a single function block and do an if 1 = 2 \< 3 (for example); How do I set the value into a variable, that is specific to a topic; so as the message comes in they are all msg.payload; but I need to split them up and place in the correct variable.

I've only ever had one variable or one JSON string come into the function block; not multipe messages.

Cheers,  
Ant

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 April 2022 19:46 UTC](https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524/4 "2022-04-20T19:46:53Z")

</div>

You can join the 3 messages with a join node set to manual and key value object, you use the 3 different topics to create a payload. Try it and see what you get. You can set the join on a count or a time out, or you can send msg.complete to output the new combined object.  
There is a example in the [cookbook](https://cookbook.nodered.org/basic/join-streams) , and many in this forum.

---

<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:** [19 June 2022 19:47 UTC](https://discourse.nodered.org/t/multiple-json-message-into-one-function-node/61524/5 "2022-06-19T19:47:05Z")

</div>

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