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:


Sample Buffer:


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.


You can ignore invalid payloads :

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

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