Unexpected token P in JSON at position 2

Hi all,

I have a mistake error in a json node. data's input is from a lora transmission using a serial communication at 9600bauds input node

the schematic is node "serial" using tty/USB1 --------> node "Json " -----> "debug" decode json
|--------> "debug" lora rx

se under the debug message . I have tested the json message in json validator with success.

2/12/2023, 11:11:55 AMnode: lora rx
msg.payload : string[116]
"{ Produit : 0, ruche : 0, masse : 0.00, temperature : 0.00, humidite : 0.00, temp_ambiante : 0.00, power12v : 0.00 }"

2/12/2023, 11:12:05 AMnode: decode json lora inputmsg : string[40]
"Unexpected token P in JSON at position 2"

I don't know why I have Unexpected token P in JSON at position 2

thanks for your reply

The problem may be that as much as it LOOK LIKE a JSON message it may not be.

What settings do you have in the JSON node?

IDEALLY the message should look like this:
"{"Produit" : 0, "ruche":0, "masse"; 0.00 and so on.

That the " are missing around Produit COULD be causing the problem.

Sorry, I am not an expert, but that is the first thing that catches my eye.

Did you feed it into the validator including the quotes? If so then it will pass because any string enclosed by quotes is valid JSON. The quotes shown in the debug output are just to indicate that it is a string, they are not actually present in the string.
@Trying_to_learn is correct, the keys must be enclosed in quotes.

Hi "Trying to learn" and Colin

I verify the same message who is in my first post with JSON Formatter & Validator and the result is ok .


but "Trying to learn" has written to add quote to "produit" and others topic . This is the solution . json node need quotes.

2/13/2023, 10:44:07 AMnode: lora rxmsg.payload : string[136]
"{ " Produit " :  0, " ruche " : 0," masse " : 0.00, "temperature" : 0.00, "humidite" : 0.00, "temp_ambiante" : 0.00, "power12v" : 0.00 }"
2/13/2023, 10:44:08 AMnode: jsonmsg.payload : Object
{ Produit : 0, ruche : 0, masse : 0, temperature: 0, humidite: 0 … }
2/13/2023, 10:44:08 AMnode: split

Thanks all

If this is your msg then I doubt you did things correctly since this ↑ is not valid JSON.

1 Like

It is not a good idea to put spaces between Produit, ruche, masse and the quotes.
The first element of the object will become msg.payload[" Produit "] not msg.payload.Produit.

ok jbudd .

I have removed the space between the quotes and the text.


1 Like

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