JSON Node unexpected token

Hi all,

I wrote a little program which sends a timestamp and Lifebit to Nodered via TCP.
Most of the time it works fine, but sometimes the JSON-node throws an error:

grafik

Sample Buffer:

[123,13,10,32,32,34,85,104,114,122,101,105,116,34,58,32,34,50,48,50,51,45,48,53,45,49,51,32,50,51,58,50,49,58,49,52,34,44,13,10,32,32,34,76,105,102,101,98,105,116,34,58,32,102,97,108,115,101,13,10,125]

flow snippet:

Any idea what causes this error?

@nico25 The sample buffer you've provided is valid JSON, so doesn't tell us anything about the case where you are hitting an error.

Your flow is receiving data over the TCP port, and you are assuming each message it sends corresponds to a whole intact message. However it is possible that you are receiving a whole object plus the start of the next. Something like this:

{ "Uhrzeit": "2023-05-13 23:21:14", "Lifebit": false }{  "Uhrz

The only way to be sure would be to add a Debug node on the output of the TCP node so you can see exactly what it is receiving.

You were right. Usually the buffer length is 60 if the lifebit is true and 61 if it is false, for whatever reason every 2-3 minutes the buffer contains both telegrams and therefore is 121.

grafik

You can ignore invalid payloads :

if (msg.payload.length <= 61) {
   // do something and continue to next flow
  return
}
else {
  // alert only
}
1 Like

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