Formatting MQTT Data

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.

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

Any ideas?

Thank you

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.

1 Like

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

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]?

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

1 Like

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 ...

you have to put msg. in front

1 Like

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