Buffer to JSON Obj Problem

I have a TCPIP node that outputs as follows;
image

If I use a function node to do msg.payload.toString() I get;
image

But if I then use a JSON node I get this;
image

Position 1444 in the buffer is this;
image

Ive tried all sorts and just cant find anything that works.

Any pointers would be appreciated.

Thx

From the looks of your msg.payload string there's a return character at the end of the string.
Try stripping that out in your function node before the JSON node.

it's the 00 at the end that may be the issue - but yes - either way - stripping it off with .substr is probably the easiest way to go.

Many thanks for the prompt responses.

var str = msg.payload.toString();
msg.payload = str.substr(0,1443);
return msg;

Works like a charm!

.....until payload length changes then it fails. Changed function to;

var str = msg.payload.toString();
msg.payload = str.replace(/\0/,"");
return msg;
1 Like

just fr completeness you can also use .slice - which will take negative numbers to count from the end so

msg.payload = msg.payload.toString().slice(0,-1);
return msg;
1 Like