# Formatting MQTT Data

**URL:** <https://discourse.nodered.org/t/formatting-mqtt-data/39773>\
**Category:** General\
**Created:** [26 January 2021 12:21 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773 "2021-01-26T12:21:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [26 January 2021 12:21 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/1 "2021-01-26T12:21:17Z")

</div>

Hello folks,

Currently having an issue which I imagine is very simple but so simple I can`t find the answer.

I`ve set up a MQTT server to write to a regiter remotely. The Msg.paylod comes through as indented by "" and I need to figure out how to unindent the message.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61934a20503a44c703a895383c8cb5b90784a7f4.png)

Attached I thought I would make is so that msg.payload.data [0] == msg.payload however this doesnt work.

Any ideas?

Thank you

---

<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:** [26 January 2021 12:52 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/2 "2021-01-26T12:52:19Z")

</div>

Set the mqtt node to output a parsed json object, then the string will be turned into a javascript object, and you will be able to access the data in msg.payload.

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [26 January 2021 14:09 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/3 "2021-01-26T14:09:43Z")

</div>

Hey ,

Thank you so much for your help ,

So the data Im reading is split into data and a buffer. If I was hoping to specify an exact point in that array what code would I put to call the msg.payload?  
For example

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cc6bc362d3bf25b04033858cd12f4e29e2109da.jpeg)

this is the data I`m sending and recieving , if I wanted to call specifically row 4 "12324" would that be msg.payload[0][4]?

---

<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:** [26 January 2021 14:17 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/4 "2021-01-26T14:17:53Z")

</div>

To the right of 4: 12324, when you hoover the cusor you will see a icon that says copy path, use that to find the path

i can not see the full object in the image, but to guess i would think `msg.payload.data[4]`

read here for better explanation  
[https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message](https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message)

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [26 January 2021 14:36 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/5 "2021-01-26T14:36:55Z")

</div>

Wow I never knew that thank you ! So when I call the payload path which is payload.data[4] I recieve this error message saying the payload is not definied? I thought I`d try the Number oprand but this doesnt solve the problem ...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0bdad3ee0742962420ea68f4795d840ad76ac68f.jpeg)

---

<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:** [26 January 2021 14:44 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/6 "2021-01-26T14:44:19Z")

</div>

you have to put msg. in front

---

<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:** [9 February 2021 14:44 UTC](https://discourse.nodered.org/t/formatting-mqtt-data/39773/7 "2021-02-09T14:44:27Z")

</div>

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