# Separate MQTT JSON message

**URL:** <https://discourse.nodered.org/t/separate-mqtt-json-message/22766>\
**Category:** General\
**Created:** [7 March 2020 16:15 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766 "2020-03-07T16:15:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardoluiztodero](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@eduardoluiztodero](https://discourse.nodered.org/u/eduardoluiztodero)\
**Post date:** [7 March 2020 16:15 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/1 "2020-03-07T16:15:10Z")

</div>

Hello guys, I'm developing an IoT project and I'm sending data from my ESP32 to an MQTT broker and I want to build a dasboard on Node-red. I'm sending it in JSON form, because I read that this is the best form when it comes to MQTT. How do I separate the variables that are inside JSON? For example, I will have readings from temperature, humidity and air quality sensors, all coming together in JSON. I want to separate this information to set up a dasboard .. Follow what I have done so far, my sensors haven't arrived yet, that's why the strange numbers.

Thanks!!

 ![duvida](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3ba6fe38665bf834c58479e6854edebb1c9903f.png)

---

<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:** [7 March 2020 16:27 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/2 "2020-03-07T16:27:43Z")

</div>

Set the MQTT In node to return a Parsed JSON object (it is in the node configuration). That will parse the JSON string and convert it to a javascript object.

---

<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:** [7 March 2020 16:32 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/3 "2020-03-07T16:32:47Z")

</div>

I see you are writing the data as an array, it might be better to write the values to separate properties rather than relying on the array order, so in the ESP you could send  
`{"temperature": 21, "humidity": 45, ...}`  
then after it comes out of the MQTT node you will be able to use`msg.payload.temperature`.

---

<div class="post-metadata">

**Author:** ![eduardoluiztodero](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@eduardoluiztodero](https://discourse.nodered.org/u/eduardoluiztodero)\
**Post date:** [7 March 2020 17:43 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/4 "2020-03-07T17:43:36Z")

</div>

I can't configure ESP in this format {"temperature": 21, "humidity": 45, ...} because I am sending an entire package from another LoRa device. So I get a buffer with all this data and send it to MQTT. Do you know any function in javascript that I can get each position of this array?

---

<div class="post-metadata">

**Author:** ![eduardoluiztodero](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@eduardoluiztodero](https://discourse.nodered.org/u/eduardoluiztodero)\
**Post date:** [7 March 2020 17:44 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/5 "2020-03-07T17:44:42Z")

</div>

![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/389742242d9bd3e5cae53f5cae8a493026b94f5b.png)

---

<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:** [7 March 2020 17:59 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/6 "2020-03-07T17:59:19Z")

</div>

The usual array methods will do it. `msg.payload.valores[0]` for the first one, `[1]` for the second, and so on.

---

<div class="post-metadata">

**Author:** ![eduardoluiztodero](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@eduardoluiztodero](https://discourse.nodered.org/u/eduardoluiztodero)\
**Post date:** [7 March 2020 18:09 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/7 "2020-03-07T18:09:59Z")

</div>

Ah yes, it works! But I wanted to separate right after MQTT to build a dashboard .. I'm still learning how to use Node-red, I apologize for the simple questions

 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/090f9aeb66090de782cce00ecfb37580b7289631.png)

---

<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:** [7 March 2020 18:21 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/8 "2020-03-07T18:21:25Z")

</div>

You shouldn't need to separate them, you can tell the dashboard node which item to display.

---

<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:** [7 March 2020 18:23 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/9 "2020-03-07T18:23:44Z")

</div>

But if you did want to extract one, use a Change node to Move `msg.payload...` To `msg.payload`

---

<div class="post-metadata">

**Author:** ![eduardoluiztodero](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@eduardoluiztodero](https://discourse.nodered.org/u/eduardoluiztodero)\
**Post date:** [7 March 2020 18:29 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/10 "2020-03-07T18:29:28Z")

</div>

I did it !! Thank you! Now I need to organize things on my dasborad .. Thank you very much!

---

<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:** [21 March 2020 18:29 UTC](https://discourse.nodered.org/t/separate-mqtt-json-message/22766/11 "2020-03-21T18:29:28Z")

</div>

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