# Split a three value message, and create 3 messages with the count as part of the topic

**URL:** <https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207>\
**Category:** General\
**Created:** [23 May 2024 18:21 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207 "2024-05-23T18:21:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sspence](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sspence](https://discourse.nodered.org/u/sspence)\
**Post date:** [23 May 2024 18:21 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/1 "2024-05-23T18:21:59Z")

</div>

I'm receiving a message like this from mqtt -

transformer/temperature\_PL6X10 33  
transformer/temperature\_PL6X12 [50, 40, 43]  
transformer/temperature\_PL6X13 [59, 48, 49]

I want to output:

transformer/temperature\_PL6X10, 33  
transformer/temperature\_PL6X12\_1, 50  
transformer/temperature\_PL6X12\_2, 40  
transformer/temperature\_PL6X12\_3, 43  
transformer/temperature\_PL6X13\_1, 59  
transformer/temperature\_PL6X13\_2, 48  
transformer/temperature\_PL6X13\_3, 49

split gives me 3 messages with the same topic, I need to increment the topic # if there are multiple values.

---

<div class="post-metadata">

**Author:** ![sspence](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sspence](https://discourse.nodered.org/u/sspence)\
**Post date:** [23 May 2024 19:31 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/2 "2024-05-23T19:31:35Z")

</div>

Ended up splitting the messages in python before publishing to the broker. Now node-red has an easier time inserting into influx.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 May 2024 21:37 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/3 "2024-05-24T21:37:42Z")

</div>

I'm not understanding the incoming messages.

Is that three examples of messages or the continuation of the original message?

What do you mean _increment the topic #_?

What is the topic you want it to be?

---

<div class="post-metadata">

**Author:** ![sspence](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sspence](https://discourse.nodered.org/u/sspence)\
**Post date:** [28 May 2024 12:09 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/4 "2024-05-28T12:09:57Z")

</div>

From this:

transformer/temperature\_PL6X12 [50, 40, 43]

I want this:

transformer/temperature\_PL6X12\_1 50  
transformer/temperature\_PL6X12\_2 40  
transformer/temperature\_PL6X12\_3 43

---

<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:** [28 May 2024 12:37 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/5 "2024-05-28T12:37:31Z")

</div>

Arrays can be iterated using the split node.

Then you update the topic of each message emitted from the split node to append "\_n" to the topic (where `n` is the index + 1)

NOTE: The split node adds `msg.parts` to each message, which contains the `index`. (see built in help of split node) (add a debug node to the output of the split node (set to show complete message) to this for your own understanding)

Demo:

```auto
[{"id":"c61dd404de610e73","type":"inject","z":"06a2836c9f2ae124","name":"transformer/temperature_PL6X12 [50, 40, 43]","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"transformer/temperature_PL6X12","payload":" [50, 40, 43]","payloadType":"json","x":1410,"y":460,"wires":[["efac7f31e3da5f23"]]},{"id":"cefe06e6888df2bf","type":"split","z":"06a2836c9f2ae124","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":1370,"y":400,"wires":[["6fdd372739f2be43"]]},{"id":"6fdd372739f2be43","type":"change","z":"06a2836c9f2ae124","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"topic & \"_\" & (parts.index+1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1510,"y":400,"wires":[["8ee933d648549309"]]},{"id":"8ee933d648549309","type":"debug","z":"06a2836c9f2ae124","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1820,"y":400,"wires":[]},{"id":"efac7f31e3da5f23","type":"switch","z":"06a2836c9f2ae124","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"array","vt":"array"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1670,"y":460,"wires":[["cefe06e6888df2bf"],["c9904fc2b7f3ee69"]]},{"id":"c9904fc2b7f3ee69","type":"debug","z":"06a2836c9f2ae124","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1820,"y":480,"wires":[]},{"id":"89333c91338bce96","type":"inject","z":"06a2836c9f2ae124","name":"transformer/temperature_PL6X13 55","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"transformer/temperature_PL6X13","payload":"55","payloadType":"num","x":1380,"y":520,"wires":[["efac7f31e3da5f23"]]},{"id":"58ddd82492454565","type":"inject","z":"06a2836c9f2ae124","name":"transformer/temperature_PL6X14 \"some text\"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"transformer/temperature_PL6X14","payload":"some text","payloadType":"str","x":1410,"y":580,"wires":[["efac7f31e3da5f23"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/798564678c4463ce0195c4a9bc0ce327881400b0.png)

---

<div class="post-metadata">

**Author:** ![sspence](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sspence](https://discourse.nodered.org/u/sspence)\
**Post date:** [12 June 2024 12:07 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/6 "2024-06-12T12:07:48Z")

</div>

Thank you!

---

<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:** [10 September 2024 12:08 UTC](https://discourse.nodered.org/t/split-a-three-value-message-and-create-3-messages-with-the-count-as-part-of-the-topic/88207/7 "2024-09-10T12:08:24Z")

</div>

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