Unexpected token D in JSON at position 0

Hi,

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

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.

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

What could cause the error here?

What kind of node is

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

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?

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.

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

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

1 Like

yes because this is a json

default:

afbeelding

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.

This is what i see in the debug window:

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

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.

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

Well that is where the problem is then

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

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?

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?

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

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

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