# Having trouble parsing this message

**URL:** https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171
**Category:** General
**Created:** [29 August 2020 04:01 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171 "2020-08-29T04:01:37Z")
**Posts on this page:** 20
**Page:** 1

<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: [29 August 2020 04:01 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/1 "2020-08-29T04:01:38Z")

</div>

I have an `exec` node running some code.

I connect to the `return code` output. (The bottom one)

This is the message coming out:

```auto
{"topic":"DO_THIS","qos":2,"retain":false,"_msgid":"755998b4.052328","payload":{"code":0}}

```

I open the `payload` part and copy the value. I'm guessing it is `0`.  
But when I paste it I get:

`0` but it isn't quite that easy.

I put that into a `switch` node and it never gets through.

Wondering what is going on, I copy the value and paste it.

# Things get weird now.

Screen shot time.

This is an arbitrary `function` node.

Note where the cursor is.

 ![Screenshot from 2020-08-29 13-58-18](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92e1ffc4bc014120b451d1d45a839753e9484709.png)

So then I press _paste_ and this is what I get:

 ![Screenshot from 2020-08-29 13-58-24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83473b5b10c26f3fbf0209efedcd786f19701d68.png)

Somehow there is a _carriage return_ built into what I copied.

I'm confused.

What is going on?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [29 August 2020 05:16 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/2 "2020-08-29T05:16:49Z")

</div>

I can reproduce. It only happens if i copy the value from the debug window or click copy value. If another source is used (vscode/sublime), it does not happen.

There might be an special hidden character. (i couldn't find it).

---

<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: [29 August 2020 05:26 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/3 "2020-08-29T05:26:49Z")

</div>

Phew. It isn't just me.

Ok. Not a big deal. I will work around the problem.

Appreciated you validating it wasn't me doing something stupid.

---

<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: [29 August 2020 07:05 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/4 "2020-08-29T07:05:37Z")

</div>

> [@Trying\_to\_learn](#):
>
> I put that into a `switch` node and it never gets through.

That suggests you did not do it correctly. Show us what you tried.

---

<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: [29 August 2020 07:07 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/5 "2020-08-29T07:07:25Z")

</div>

_show_?

I have the `debug` node, expand the tree to see what I want to get, click on the clipboard icon.  
It says `copied to clip board`.

I then pate it in the `function` node at the end of the line and the `0` from the clipboard is at the start of the line.

---

<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: [29 August 2020 07:38 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/6 "2020-08-29T07:38:09Z")

</div>

Doesnt happen in Chrome on Windows - might be a browser or OS thing?

 ![GXFiQsOOCR](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50992b9f9e0227488decd46a805a0ee91d5d4fcb.gif)

I tried with the debug set to show msg.payload AND showing full message - same result.

---

<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: [29 August 2020 07:39 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/7 "2020-08-29T07:39:03Z")

</div>

(How are you doing this _magic_?) 😉

Screen recordings.

---

<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: [29 August 2020 07:43 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/8 "2020-08-29T07:43:29Z")

</div>

sharex (windows only)

> **[ShareX - Screen capture, file sharing and productivity tool](https://getsharex.com/)**
>
> ShareX is a free and open source program that lets you capture or record any area of your screen and share it with a single press of a key. It also allows uploading images, text or other types of files to many supported destinations you can choose...

For linux, there is **peek** and others though not as feature rich as sharex

---

<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: [29 August 2020 07:46 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/9 "2020-08-29T07:46:42Z")

</div>

Ah, windows.

Not much good for Ubuntu.

Ok, I have word around it by changing the `==` to `contains`.

That works.

---

<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: [29 August 2020 07:55 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/10 "2020-08-29T07:55:06Z")

</div>

> [@Trying\_to\_learn](#):
>
> _show_ ?

You said you tried it in a Switch node but it didn't work, but you haven't showed us what you tried in the switch node. Then you went on to talk about a function node problem.

---

<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: [29 August 2020 07:57 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/11 "2020-08-29T07:57:47Z")

</div>

Originally the node was like this:

```auto
[{"id":"7f0765ad.dfa1f4","type":"switch","z":"5b95490e.a46ab8","name":"Ok/Error","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"127","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1610,"y":690,"wires":[["4fd1597d.7d477"],["9c0f56c2.186e9"]]}]

```

But works when it is set as:

```auto
[{"id":"7f0765ad.dfa1f4","type":"switch","z":"5b95490e.a46ab8","name":"Ok/Error","property":"payload.code","propertyType":"msg","rules":[{"t":"cont","v":"0","vt":"num"},{"t":"cont","v":"127","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1610,"y":690,"wires":[["4fd1597d.7d477"],["9c0f56c2.186e9"]]}]

```

So I was just curious why the payload isn't as I am copying from the `debug` node.

I only went into the `function` node to paste the copied `msg.payload` to see what node-red thinks of it.

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [29 August 2020 08:10 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/12 "2020-08-29T08:10:56Z")

</div>

== is working for me.  
besides if you put contains not only 0 will pass but 10 , 2022 etc whatever contains zero and that may not be what you want.

you sure you are setting **msg.payload.code** in the switch node ? and not simply msg.payload ?

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

---

<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: [29 August 2020 08:19 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/13 "2020-08-29T08:19:38Z")

</div>

Yes, I am sure that is the message structure.

Alas it is an artefact of my early `MQTT` stuff.

It is the output of an `exec` node. It only really puts out `0` for good, and `127` for errors.

That is all I want to get from the output.

---

<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: [29 August 2020 08:21 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/14 "2020-08-29T08:21:38Z")

</div>

I think you're on to something.

The fact Andrew states he solved it by using `contains` instead of `==` suggest he was comparing to string `0` not number `0`

> [@Trying\_to\_learn](#):
>
> Ok, I have word around it by changing the `==` to `contains` .

Not that it should matter but `payload.code` is definitely a number so your example would be the correct solution.

---

<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: [29 August 2020 08:23 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/15 "2020-08-29T08:23:56Z")

</div>

I was suspicious that it was a text, which also lead me to paste it in a `function` node.

When it was pasted in the node, it was orange so I take it that it is a number.

---

<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: [29 August 2020 08:26 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/16 "2020-08-29T08:26:23Z")

</div>

> [@Trying\_to\_learn](#):
>
> When it was pasted in the node, it was orange so I take it that it is a number.

More like...

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

---

<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: [29 August 2020 08:29 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/17 "2020-08-29T08:29:22Z")

</div>

Ok. I was talking about the `0` to the left of `this is just some text`.

But yes: correct.

---

<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: [29 August 2020 08:40 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/18 "2020-08-29T08:40:22Z")

</div>

Is this from o/p 3 of a switch node?  
Is the exec node feeding direct into the switch node or is there anything at all in between?  
Can you show us the config of the exec node? I want to try and replicate the problem.  
I don't even know what "contains" means if the type is number.

---

<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: [29 August 2020 08:40 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/19 "2020-08-29T08:40:53Z")

</div>

> [@Trying\_to\_learn](#):
>
> Ok. I was talking about the `0` to the left of `this is just some text` .

Yes, but you copied that from the debug

A `0` in the JS editor is a number because it has no quotes.

The debug does not copy `"` quotes so a string `"0"` zero would copy and paste as `0`

In other words, pasting the value means nothing - how its presented in the object is what matters.

in other words, it IS / WAS a number so use the `==` number in the switch (not contains)

---

<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: [29 August 2020 08:42 UTC](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171/20 "2020-08-29T08:42:19Z")

</div>

No, via a `delay` node set to delay the message for `5` seconds.

[Next page](https://discourse.nodered.org/t/having-trouble-parsing-this-message/32171.md?page=2)
