# Splitting Payload Values

**URL:** <https://discourse.nodered.org/t/splitting-payload-values/57805>\
**Category:** General\
**Created:** [5 February 2022 02:22 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805 "2022-02-05T02:22:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan780](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ryan780/32/22974_2.png) [@ryan780](https://discourse.nodered.org/u/ryan780)\
**Post date:** [5 February 2022 02:22 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/1 "2022-02-05T02:22:40Z")

</div>

So, I know there must be an easier way to do this than using a function node, which is what I am doing currently. So, I have an incoming messages which as multiple values stored as JSON data within msg.payload. But the subsequent nodes need the individual values in msg.payload. So, what I currently doing in a function node is the following:

```auto
msg1 = {"payload":msg.payload.VALUE1`};
msg2 = {"payload":msg.payload.VALUE2};
msg3 = {"payload":msg.payload.VALUE3};
msg4 = {"payload":msg.payload.VALUE4};
return [msg1,msg2,msg3,msg4]

```

But that doesn't copy over all the over values included inside of the msg object. I know I could start by creating the new msgs as a copy of msg but I wanted to see if there was a simpler way to tear these apart than what i am currently doing. Thanks!!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [5 February 2022 04:19 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/2 "2022-02-05T04:19:02Z")

</div>

> So, what I currently doing in a function node is the following:

The function node will now have 4 output ports and this is always consistent ?

Can you show an example of your flow and/or what `msg` goes into the function node and what you are expecting it to output ? What you are showing here could be done with a switch node and a change node (or 4)

---

<div class="post-metadata">

**Author:** ![ryan780](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ryan780/32/22974_2.png) [@ryan780](https://discourse.nodered.org/u/ryan780)\
**Post date:** [5 February 2022 04:46 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/3 "2022-02-05T04:46:52Z")

</div>

Yes, it will have 4 outputs because I am trying to feed the the different values input in a JSON string into different messages. I know I could do it with 4 different change nodes too....but that just seems more complicated than one function node.

You couldn't really do it with a switch node because I want 4 outputs each time, not 1 output on one of 4 paths each time. It would have to be done with 4 change nodes.

An example of the msg.payload input would be:

`{"VALUE1": 1, "VALUE2":2,"VALUE3":3, "VALUE4":4}`

And the input for the following nodes need msg.payload to equal 1,2,3 or 4. so, splitting each json key into separate payloads.

---

<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:** [5 February 2022 08:08 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/4 "2022-02-05T08:08:45Z")

</div>

Without a function node...

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

```auto
[{"id":"82ad0f7b4eefceec","type":"inject","z":"85e1791bc0cd6285","name":"4 properties","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"VALUE1\": 1, \"VALUE2\":2,\"VALUE3\":3, \"VALUE4\":4}","payloadType":"json","x":1306,"y":704,"wires":[["a395f9dbf3dc84a7"]]},{"id":"a395f9dbf3dc84a7","type":"split","z":"85e1791bc0cd6285","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":1458,"y":704,"wires":[["7fd363da1faaeae7"]]},{"id":"7fd363da1faaeae7","type":"switch","z":"85e1791bc0cd6285","name":"route by topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"VALUE1","vt":"str"},{"t":"eq","v":"VALUE2","vt":"str"},{"t":"eq","v":"VALUE3","vt":"str"},{"t":"eq","v":"VALUE4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1456,"y":800,"wires":[["e0d28738aa145d72"],["30985bacbb74e0fb"],["15a51cc054d8d9a2"],["38bda349fcbbba6a"]]},{"id":"e0d28738aa145d72","type":"debug","z":"85e1791bc0cd6285","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1648,"y":768,"wires":[]},{"id":"30985bacbb74e0fb","type":"debug","z":"85e1791bc0cd6285","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1648,"y":800,"wires":[]},{"id":"15a51cc054d8d9a2","type":"debug","z":"85e1791bc0cd6285","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1648,"y":832,"wires":[]},{"id":"38bda349fcbbba6a","type":"debug","z":"85e1791bc0cd6285","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1648,"y":864,"wires":[]}]

```

  

* * *
  

### NOTE (just in case you overlooked this)

many people split a `msg` into to multiple outputs when really all they need to do is use the relevant property (e.g `msg.payload.VALUE1`) in then next node. for example...

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

---

<div class="post-metadata">

**Author:** ![ryan780](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ryan780/32/22974_2.png) [@ryan780](https://discourse.nodered.org/u/ryan780)\
**Post date:** [5 February 2022 11:25 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/5 "2022-02-05T11:25:36Z")

</div>

> [@Steve-Mcl](#):
>
> many people split a `msg` into to multiple outputs when really all they need to do is use the relevant property (e.g `msg.payload.VALUE1` ) in then next node. for example...

As I state a couple of time, the nodes that I am using don't allow me to configure the input. For example the dashboard switch node. You have no way of configuring what that node will use for an input. It only allows msg.payload. if you have a way around that, I am all ears.

---

<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:** [5 February 2022 11:30 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/6 "2022-02-05T11:30:44Z")

</div>

> [@ryan780](#):
>
> > [@Steve-Mcl](#):
> >
> > all they need to do is use the relevant property (e.g `msg.payload.VALUE1` ) in then next node. for example...
> 
> As I state a couple of time, the nodes that I am using don't allow me to configure the input

That was aimed more at future readers of the thread (I did say "many people")

> [@ryan780](#):
>
> For example the dashboard switch node

No, in these cases, your only option is to move the value to `msg.payload` (or make a feature request to the maintainer)

Back to your original question

> [@ryan780](#):
>
> So, I know there must be an easier way to do this than using a function node,

Did my demo flow not work for you?

---

<div class="post-metadata">

**Author:** ![ryan780](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ryan780/32/22974_2.png) [@ryan780](https://discourse.nodered.org/u/ryan780)\
**Post date:** [5 February 2022 11:33 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/7 "2022-02-05T11:33:28Z")

</div>

That seems more complicated than 1 function node. I could have sworn I remembered reading about a node that would simply parse based on json key value. I was hoping someone might have heard of it too. Maybe it was just wishful thinking.

---

<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:** [6 April 2022 13:27 UTC](https://discourse.nodered.org/t/splitting-payload-values/57805/9 "2022-04-06T13:27:40Z")

</div>

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