# JSON Node unexpected token

**URL:** <https://discourse.nodered.org/t/json-node-unexpected-token/78806>\
**Category:** General\
**Created:** [30 May 2023 07:38 UTC](https://discourse.nodered.org/t/json-node-unexpected-token/78806 "2023-05-30T07:38:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico25](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nico25](https://discourse.nodered.org/u/nico25)\
**Post date:** [30 May 2023 07:38 UTC](https://discourse.nodered.org/t/json-node-unexpected-token/78806/1 "2023-05-30T07:38:36Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/53e6d81099619c95a85e3824ed9bb57f3f441f9e.png)

Sample Buffer:

```auto
[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:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/6265782982df8aeba401c64d25e876a42b2b827a.png)

Any idea what causes this error?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 May 2023 07:59 UTC](https://discourse.nodered.org/t/json-node-unexpected-token/78806/2 "2023-05-30T07:59:38Z")

</div>

@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:

```auto
{ "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.

---

<div class="post-metadata">

**Author:** ![nico25](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@nico25](https://discourse.nodered.org/u/nico25)\
**Post date:** [30 May 2023 08:07 UTC](https://discourse.nodered.org/t/json-node-unexpected-token/78806/3 "2023-05-30T08:07:52Z")

</div>

> [@knolleary](#):
>
> ay 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43d773a5f28207ae7e0598e8237492a8d7d0259b.png)

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [30 May 2023 13:36 UTC](https://discourse.nodered.org/t/json-node-unexpected-token/78806/4 "2023-05-30T13:36:51Z")

</div>

You can ignore invalid payloads :

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

```

---

<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:** [29 July 2023 13:37 UTC](https://discourse.nodered.org/t/json-node-unexpected-token/78806/5 "2023-07-29T13:37:18Z")

</div>

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