# Help splitting mqtt message into parts

**URL:** https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696
**Category:** General
**Created:** [12 April 2020 12:30 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696 "2020-04-12T12:30:21Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![grumpywhale](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@grumpywhale](https://discourse.nodered.org/u/grumpywhale)
#### Post date: [12 April 2020 12:30 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/1 "2020-04-12T12:30:21Z")

</div>

I am trying to move from using a pi as a sensor to a d1mini using tasmoto, i have the sensor working and publishing to a topic that works, and nodered will pick up the string. However, it comes accross as a single string rather than the parts i would need to show like temp and humidity.

"{"Time":"1970-01-01T00:00:12","AM2301":{"Temperature":23.6,"Humidity":51.0,"DewPoint":12.9},"TempUnit":"C"}"

so i need to use one of the nodes to split this message up into its parts, ive tried change and function but cant figure it out, and no matter what mix of searches i use in google i cant find the right one to get this split up. Any help... please

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [12 April 2020 12:37 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/2 "2020-04-12T12:37:06Z")

</div>

You are receiving a JSON String. Use the Json Node from the parser section of the palette to parse it to a javascript object. Afterwards you can use the change node to access the individual object properties.

Johannes

---

<div class="post-metadata">

### Author: ![grumpywhale](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@grumpywhale](https://discourse.nodered.org/u/grumpywhale)
#### Post date: [12 April 2020 12:53 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/3 "2020-04-12T12:53:57Z")

</div>

![Capture1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/882d564b655c68fba9772d714ff97522d0e96143.png)  
 ![Capture2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/53676a1a5a2c896ee2ad61a8e5ecad94bb7c2d9a.png)  
 ![result](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da78423d84918245b6657bae762738bf17508a77.png)

this results in same output but better format

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [12 April 2020 13:03 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/4 "2020-04-12T13:03:14Z")

</div>

The beauty is that you can now for example access the temperature if you use the change node with set` msg.payload` to `msg.payload.AM2301.Temperature`  
This will give you just the temperature as a payload.  
Converting it to an object gives you the option to access any of its value from a function, a change node or as a routing property in a switch node.  
You can easily get the path to a certain value when you hover over it in the debug tab and click on the copy path icon.  
Johannes

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [12 April 2020 13:07 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/5 "2020-04-12T13:07:31Z")

</div>

This is really useful to understand for working with the message object that you have now that you used the Json parser [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)  
it also talks about exactly this topic of JSON strings and javascript objects

---

<div class="post-metadata">

### Author: ![grumpywhale](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@grumpywhale](https://discourse.nodered.org/u/grumpywhale)
#### Post date: [12 April 2020 13:10 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/6 "2020-04-12T13:10:46Z")

</div>

yup that got it, i had to use another change node to grab the temperature but who cares how many IT WORKS!!!!!!

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 April 2020 13:15 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/7 "2020-04-12T13:15:22Z")

</div>

If you are using the MQTT In node then if you select the Output as Parsed JSON then it will automatically convert the string to an object so you don't need the JSON node.

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [12 April 2020 13:16 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/8 "2020-04-12T13:16:37Z")

</div>

forgot about that 🙈

---

<div class="post-metadata">

### Author: ![grumpywhale](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@grumpywhale](https://discourse.nodered.org/u/grumpywhale)
#### Post date: [12 April 2020 13:22 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/9 "2020-04-12T13:22:28Z")

</div>

Both methods work, thanks allot. Have literally been trying to sort this for 5 hours... (after like a week getting the sensor to work in the first place)  
Thank you to all... much much appreciated.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 April 2020 13:25 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/10 "2020-04-12T13:25:10Z")

</div>

If you just want to display this in a gauge or text node then the display node can be configured to select a particular part of the payload to display, so you might not need the change node. I think how to do it is described in the info panel for the nodes, I always have to look it up, I can never remember the syntax.

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [12 April 2020 13:27 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/11 "2020-04-12T13:27:11Z")

</div>

`{{msg.payload.AM2301.Temperature}}`  
double curly braces

---

<div class="post-metadata">

### Author: ![grumpywhale](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@grumpywhale](https://discourse.nodered.org/u/grumpywhale)
#### Post date: [12 April 2020 13:31 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/12 "2020-04-12T13:31:20Z")

</div>

well thats me redoing all my mqtt topics to gauges... 😁

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 April 2020 13:34 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/13 "2020-04-12T13:34:41Z")

</div>

Now if we could just make it telepathic you wouldn't need to say you needed the MQTT or Gauge nodes either. 🙂

---

<div class="post-metadata">

### Author: ![grumpywhale](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@grumpywhale](https://discourse.nodered.org/u/grumpywhale)
#### Post date: [12 April 2020 13:44 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/14 "2020-04-12T13:44:28Z")

</div>

gauge nodes fair enough, but did say mqtt at the start, does this apply to any of the display nodes you can go straight from mqtt as json to the node to display that bit?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 April 2020 13:49 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/15 "2020-04-12T13:49:31Z")

</div>

It is nothing to do with MQTT, the display node doesn't know it is coming from mqtt, it just gets an object. I don't know whether all of them have that option but certainly most do. Easy enough to find out with any particular one you are interested in. You can also set the display format if you want (number of decimal places for example).

---

<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: [11 June 2020 13:49 UTC](https://discourse.nodered.org/t/help-splitting-mqtt-message-into-parts/24696/16 "2020-06-11T13:49:36Z")

</div>

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