# Error after deploying a project

**URL:** <https://discourse.nodered.org/t/error-after-deploying-a-project/83017>\
**Category:** General\
**Created:** [19 November 2023 21:11 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017 "2023-11-19T21:11:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebolisa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ebolisa/32/89203_2.png) [@ebolisa](https://discourse.nodered.org/u/ebolisa)\
**Post date:** [19 November 2023 21:11 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/1 "2023-11-19T21:11:35Z")

</div>

Hi,

I get the error shown in the image only once and at start of the project.  
What could cause it?  
TIA

 ![Captura de pantalla (58)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b0c8f2dc21777479f76aebe660ddf6ccfcd3880e.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:** [19 November 2023 21:25 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/2 "2023-11-19T21:25:20Z")

</div>

Configure the node to send a string rather than parsed json and see what the first message received is.

---

<div class="post-metadata">

**Author:** ![ebolisa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ebolisa/32/89203_2.png) [@ebolisa](https://discourse.nodered.org/u/ebolisa)\
**Post date:** [19 November 2023 23:45 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/3 "2023-11-19T23:45:09Z")

</div>

Thanks, that did it - . I had to modify my function node to parse the json data.

```auto
var msgSensor1 = { payload: 0 };
var msgSensor2 = { payload: 0 };
var msgPulse = { payload: 0 };
var msgTemp = { payload: 0 };
var msgPump = { payload: 0 };
var msgEmail = { payload: 0 }
var msgVer = { payload: 0 };

if (msg.topic !== 'nada') {
    var string = JSON.stringify(msg.payload);
    //var p = JSON.parse(string); <-- commented out
    var p = JSON.parse(msg.payload);
    msgSensor1 = { payload: parseInt(p.s1) };
    msgSensor2 = { payload: parseInt(p.s2) };
    msgPulse = { payload: p.hb };
    msgTemp = { payload: p.t };
    msgEmail = { payload: p.em };
    msgPump = { payload: p.pn };
    msgVer = { payload: p.ver };

    if (msgEmail.payload == 1 && msgPump.payload == 1){
        msgEmail.payload = 1;
    }
    else if (msgEmail.payload == 1 && msgPump.payload == 2){
        msgEmail.payload = 2;
    }
    else {
        msgEmail.payload = 0;
    }
    
    return [msgSensor1, msgSensor2, msgPulse, msgTemp, msgEmail, msgVer];
}

```

---

<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:** [20 November 2023 08:01 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/4 "2023-11-20T08:01:22Z")

</div>

> [@ebolisa](#):
>
> Thanks, that did it

That was not supposed to be a solution, what you have done is probably not the best way to solve it. What is in the first message coming in (the one that caused the json error) now that you have stopped the node from trying to parse it? Feed it into a debug node to see. If necessary, set the debug node to output to the console then run node red from a command window and you will see the debug output there.

---

<div class="post-metadata">

**Author:** ![ebolisa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ebolisa/32/89203_2.png) [@ebolisa](https://discourse.nodered.org/u/ebolisa)\
**Post date:** [20 November 2023 08:23 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/5 "2023-11-20T08:23:54Z")

</div>

Ok, any improvements for my general knowledge, is welcome 😉  
This' what I get from the mqtt receiver node:

`"{"s1": 100, "hb": 0, "pn": 0, "s2": 100, "ver": "8", "em": 0, "t": 25.0}"`

The data comes from a Rpi Pico W micro running with micropython.

Now, if I set the mqtt receiver node back to "a parsed JSON object", I get this format:

```auto
11/20/2023, 9:25:58 AM [node: Parse Json] 
(http://192.168.1.230:1880/#)
function : (error)
"SyntaxError: Unexpected token o in JSON at position 1"
11/20/2023, 9:25:58 AM [node: debug 1]
(http://192.168.1.230:1880/#)casa/rp2/soil/moist : msg.payload : Object
object
s1: 100
hb: 0
pn: 0
s2: 100
ver: "8"
em: 0
t: 27

```

and, if I set the node to "auto detect string or buffer", I get this:

```auto
11/20/2023, 9:30:26 AM node: debug 1
casa/rp2/soil/moist : msg.payload : string[72]
"{"s1": 100, "hb": 1, "pn": 0, "s2": 100, "ver": "8", "em": 0, "t": 28.0}"

```

---

<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:** [20 November 2023 09:27 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/6 "2023-11-20T09:27:27Z")

</div>

Which MQTT node are you using (full name please i.e. node-red-???????) You can go to the top right of the editor and click the 'hamburger' icon and select `Manage palette` then enter `mqtt` in the search.

---

<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:** [20 November 2023 09:42 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/7 "2023-11-20T09:42:09Z")

</div>

> [@ebolisa](#):
>
> Now, if I set the mqtt receiver node back to "a parsed JSON object", I get this format

You get an object.

If you then pass that into your function node, ` JSON.parse(msg.payload);` will throw an error

Proof:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af2144df59a67ff8a872a4b73c9cd82786fc17c5.png)

  

> [@ebolisa](#):
>
> and, if I set the node to "auto detect string or buffer", I get this

When you have a string your function node will call `var p = JSON.parse(msg.payload);` and convert the string to an object

Proof:

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

Also worthy of note: `s1` and `s2` are already numbers - calling `parseInt(p.s1)` is redundant.

Proof:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea06f5d14379078649e2a37b09b131ea8ae0976c.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:** [20 November 2023 09:55 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/8 "2023-11-20T09:55:13Z")

</div>

> [@ebolisa](#):
>
> ```auto
> 11/20/2023, 9:25:58 AM [node: Parse Json] 
> (http://192.168.1.230:1880/#)
> function : (error)
> "SyntaxError: Unexpected token o in JSON at position 1"
> 
> ```

I thought you meant that the error was coming from the MQTT node, whereas it is actually coming from the function node.

With the MQTT node set to parse the json it is receiving and output an object, it will output an object, so you don't need to parse it in the function node. You should be able to take out the stringify and the parse in the function node.

---

<div class="post-metadata">

**Author:** ![ebolisa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ebolisa/32/89203_2.png) [@ebolisa](https://discourse.nodered.org/u/ebolisa)\
**Post date:** [20 November 2023 10:52 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/9 "2023-11-20T10:52:53Z")

</div>

I guess the one it comes with the standard package as it doesn't show any names. I has two options: mqtt in and mqtt out.

---

<div class="post-metadata">

**Author:** ![ebolisa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ebolisa/32/89203_2.png) [@ebolisa](https://discourse.nodered.org/u/ebolisa)\
**Post date:** [20 November 2023 10:59 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/10 "2023-11-20T10:59:06Z")

</div>

I see what you mean. In my first post the img shows where the error was generated that's why I thought it came from the mqtt node.

---

<div class="post-metadata">

**Author:** ![ebolisa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ebolisa/32/89203_2.png) [@ebolisa](https://discourse.nodered.org/u/ebolisa)\
**Post date:** [20 November 2023 11:00 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/11 "2023-11-20T11:00:40Z")

</div>

That's one of my pending tasks: learn how to use a cmd console and not just rely on the web console. Thanks!

---

<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:** [4 December 2023 11:01 UTC](https://discourse.nodered.org/t/error-after-deploying-a-project/83017/12 "2023-12-04T11:01:25Z")

</div>

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