# Unexpected token P in JSON at position 2

**URL:** <https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098>\
**Category:** General\
**Created:** [12 February 2023 23:35 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098 "2023-02-12T23:35:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![joel14](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joel14/32/75991_2.png) [@joel14](https://discourse.nodered.org/u/joel14)\
**Post date:** [12 February 2023 23:35 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/1 "2023-02-12T23:35:22Z")

</div>

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.

```auto
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  
Joël

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 February 2023 23:43 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/2 "2023-02-12T23:43:01Z")

</div>

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.

---

<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:** [13 February 2023 07:10 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/3 "2023-02-13T07:10:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joel14](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joel14/32/75991_2.png) [@joel14](https://discourse.nodered.org/u/joel14)\
**Post date:** [13 February 2023 10:49 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/4 "2023-02-13T10:49:47Z")

</div>

Hi "Trying to learn" and Colin

I verify the same message who is in my first post with [JSON Formatter & Validator](https://jsonformatter.curiousconcept.com/#) and the result is ok .

```auto

   "ruche":0,
   "masse":0.00,
   "temperature":0.00,
   "humidite":0.00,
   "temp_ambiante":0.00,
   "power12v":0.00
}

```

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

```auto
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  
Joël

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 February 2023 10:58 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/5 "2023-02-13T10:58:26Z")

</div>

> [@joel14](#):
>
> I verify the same message who is in my first post with [JSON Formatter & Validator](https://jsonformatter.curiousconcept.com/#) and the result is ok

> [@joel14](#):
>
> `"{ Produit : 0, ruche : 0, masse : 0.00, temperature : 0.00, humidite : 0.00, temp_ambiante : 0.00, power12v : 0.00 }"`

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61fc4133a97572c189a112708b6a7e7a07aad745.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 February 2023 11:31 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/6 "2023-02-13T11:31:16Z")

</div>

> [@joel14](#):
>
> `{ " Produit " : 0, " ruche " : 0," masse " : 0.00, "temperature" : 0.00, "humidite" : 0.00, "temp_ambiante" : 0.00, "power12v" : 0.00 }`

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`.

---

<div class="post-metadata">

**Author:** ![joel14](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joel14/32/75991_2.png) [@joel14](https://discourse.nodered.org/u/joel14)\
**Post date:** [13 February 2023 18:32 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/7 "2023-02-13T18:32:42Z")

</div>

ok jbudd .

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

thanks  
joël

---

<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:** [14 April 2023 18:33 UTC](https://discourse.nodered.org/t/unexpected-token-p-in-json-at-position-2/75098/8 "2023-04-14T18:33:19Z")

</div>

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