# Unexpected token D in JSON at position 0

**URL:** <https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680>\
**Category:** General\
**Created:** [12 April 2020 07:47 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680 "2020-04-12T07:47:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 07:47 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/1 "2020-04-12T07:47:26Z")

</div>

Hi,

An incoming mqtt message, which is a string: "De frietpan is aangezet!" ,returns the following error 4 times:

```auto
12-4-2020 09:29:39node: 26a592da.b81be6
msg : string[40]
"Unexpected token D in JSON at position 0"

```

It doesn't matter if I use the JSON parser node or not. Both situations return the error (4 times)  
The only difference is that if the JSON parser is not used, the string is also returned.

```auto
12-4-2020 09:29:39node: 1889fa0d.7b68c6
domoticz/out : msg.payload : string[24]
"De frietpan is aangezet!"

```

What could cause the error here?

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 07:54 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/2 "2020-04-12T07:54:30Z")

</div>

What kind of node is

> [@gschmidt](#):
>
> 26a592da.b81be6

that gives the error? Is it the mqtt node itself? Looks like something is trying to handle a string like it was json which will not work.  
Johannes

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 08:00 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/3 "2020-04-12T08:00:35Z")

</div>

When I view the message in MQTT.fx, I see nothing strange, it just publishes: De frietpan is aangezet!

If I send the message in this format: {"msg": "De frietpan is aangezet!"}, then the message is correct without errors. is node-red expecting a format like this then?

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:04 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/4 "2020-04-12T08:04:24Z")

</div>

Nothing wrong with the message, something in Nodered is trying to do something with the payload expecting it to be a JSON. Thats why Im asking. If you click on the node id in the debug tab it will show you the node that gives this error.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 April 2020 08:05 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/5 "2020-04-12T08:05:44Z")

</div>

If you are using the MQTT In node then make sure Output is set to Auto Detect.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 April 2020 08:05 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/6 "2020-04-12T08:05:47Z")

</div>

> [@gschmidt](#):
>
> "Unexpected token D in JSON at position 0"
> 
> ```auto
> 12-4-2020 09:29:39node: 1889fa0d.7b68c6
> domoticz/out : msg.payload : string[24]
> "De frietpan is aangezet!"
> 
> ```

well that msg.payload is a string not an object. What settings do you have your `mqtt-in` node?

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:06 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/7 "2020-04-12T08:06:15Z")

</div>

> [@gschmidt](#):
>
> If I send the message in this format: {"msg": "De frietpan is aangezet!"}, then the message is correct without errors.

yes because this is a json

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 08:07 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/8 "2020-04-12T08:07:52Z")

</div>

> [@zenofmud](#):
>
> well that msg.payload is a string not an object. What settings do you have your `mqtt-in` node?

default:

![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20e88b01ec390b873c9035d8110bbfa01ac43afd.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 April 2020 08:10 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/9 "2020-04-12T08:10:21Z")

</div>

Great, now you need to find the node reporting the error. copy the node id (26a592da.b81be6) and do a FIND in the editor to find the node producing the error.

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 08:10 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/10 "2020-04-12T08:10:47Z")

</div>

This is what i see in the debug window:

 ![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/25e31ca9626cf555bda3571611ab3c599ae1c130.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 April 2020 08:11 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/11 "2020-04-12T08:11:47Z")

</div>

That error is not coming from the mqtt node. Do as suggested and search for the node generating the error.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:14 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/12 "2020-04-12T08:14:05Z")

</div>

As I said in the beginning of this thread you can double click on the node id in the debug window and it will show you the nodes throwing the errors.  
If they are not in subflows.

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 08:16 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/13 "2020-04-12T08:16:17Z")

</div>

> [@zenofmud](#):
>
> 26a592da.b81be6

When I double click on the error, node-red jumps to a JSON parser node in another flow

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 April 2020 08:16 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/14 "2020-04-12T08:16:36Z")

</div>

Well that is where the problem is then

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:17 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/15 "2020-04-12T08:17:28Z")

</div>

So the payload that you send somehow arrives there. Are you subscribing to that topic somewhere in this flow?

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 08:20 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/16 "2020-04-12T08:20:03Z")

</div>

yes I have several flows receiving messages from domoticz/out...the in coming messages are all in JSON format...  
This message is not in JSON format, just a string....could that be the error?

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [12 April 2020 08:21 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/17 "2020-04-12T08:21:20Z")

</div>

So the solution would be:

Or I send the message in a JSON format or I send the message to a different topic other than domoticz/out?

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:22 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/18 "2020-04-12T08:22:04Z")

</div>

Yes as I said you are trying to treat a String like a JSON so the JSON parser Nodes will throw errors

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:23 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/19 "2020-04-12T08:23:09Z")

</div>

If you want to send both JSONs and Strings on the same topic you will have to use something like a switch node to filter out those Strings before the Json parsers

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [12 April 2020 08:24 UTC](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680/20 "2020-04-12T08:24:04Z")

</div>

Yes separate topics for Strings and JSONs would be a solution to.

[Next page](https://discourse.nodered.org/t/unexpected-token-d-in-json-at-position-0/24680.md?page=2)
