# Change msg.payload from text to value

**URL:** <https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547>\
**Category:** General\
**Created:** [24 July 2022 21:39 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547 "2022-07-24T21:39:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joep.piet](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@Joep.piet](https://discourse.nodered.org/u/Joep.piet)\
**Post date:** [24 July 2022 21:39 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547/1 "2022-07-24T21:39:40Z")

</div>

Hi everyone,

First of all, I'm pretty new here so if I'm using the wrong termonology or my problem has to be in a different topic, I'll apologise beforehand 🙂

I'm having trouble to show coördinates on a worldmap, and I figured it might have to do with the data I send. In the msg.payload it shows the following data:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/73b17634f798a05f43b397bfb0d6b4b5c50429ee.png)

I figured that longitude and latitude should be a value instead of text and I thought that a change node could help me. I can't figure out to change the lon and lat to value without changing the name to text. I hope this sounds logic?

Underneath the code I'm using. I hope you people can help me out!

```auto
[
    {
        "id": "e8710f740e50011c",
        "type": "change",
        "z": "1c8a948f5c8de378",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$number(payload)\t",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 560,
        "wires": [
            [
                "96566d88637dabd4",
                "cbe47233a4cf6ca1"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [24 July 2022 22:08 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547/2 "2022-07-24T22:08:06Z")

</div>

Hi. Must admit I thought the worldmap was tolerant enough to accept strings, so you shouldn’t need to do that. Is there any error in the JavaScript console?

---

<div class="post-metadata">

**Author:** ![Joep.piet](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@Joep.piet](https://discourse.nodered.org/u/Joep.piet)\
**Post date:** [25 July 2022 05:30 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547/3 "2022-07-25T05:30:31Z")

</div>

Hi! Thank you for your response!

I'm not familiar with the worldmap. I tried input for lat and lon with values 50.1234 and 4.2 and it showed a point on worldmap. However, when I try to use text (I assume " " makes the outcome a text?) it doesn't show a point on worldmap. So my conclusion was that the data needs to be a value. But if this conclusion is incorrect, just let me know 🙂

To be honest, I don't really understand your question. The function itself does not show any errors, it's a simple one:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/63ce096f793d502f7022a701cc8d814d45742a7e.png)  
Is this what you mean with Javascript console?

After I use a change node:  
(unfortunately I can't insert another image, only 2 allowed)

The outcome on the debug node shows the following message:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64ee7142097408ba864251db54ff59fb12b0d207.png)

Which I kind of get, since name 'Test1' can't be a value.  
I am looking for a solution to change the variable "50.1234" and "4.2" to value, without changing "Test1" to value. I hope this makes sense.

---

<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:** [25 July 2022 08:57 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547/4 "2022-07-25T08:57:39Z")

</div>

The javascript console is part of the developer tools in the browser (nothing directly to do with node red). It would be useful to check that as I think the developers would like to know if there really is an issue with text values.

To get you going, however, add a function node containing

```auto
msg.payload.lat = Number(msg.payload.lat)
msg.payload.lon = Number(msg.payload.lon)
return msg

```

**[Edit]** But first try out Dave's example below and check whether that works for you.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2022 09:28 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547/5 "2022-07-25T09:28:51Z")

</div>

I just checked and it should work fine with strings...

here is my simple test

```auto
[{"id":"687f4fcb400b452c","type":"function","z":"70586d75232824e9","name":"function 1","func":"msg.payload = {\n name: \"Test1\",\n lat: \"50.1234\",\n lon: \"4.2\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":345,"wires":[["158f8fc82155aad6"]]},{"id":"09ccefdde71cfb4c","type":"inject","z":"70586d75232824e9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":140,"y":345,"wires":[["687f4fcb400b452c"]]},{"id":"158f8fc82155aad6","type":"worldmap","z":"70586d75232824e9","name":"","lat":"","lon":"","zoom":"","layer":"","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"false","showgrid":"false","allowFileDrop":"false","path":"/worldmap","overlist":"DR,CO,RA,DN,HM","maplist":"OSMG,OSMC,EsriC,EsriS,EsriT,EsriDG,UKOS","mapname":"","mapurl":"","mapopt":"","mapwms":false,"x":555,"y":345,"wires":[]}]

```

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

gives

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca8b529dcfde8b474d12418b4d7cd2a8fad4be04.jpeg)

---

<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:** [23 September 2022 09:29 UTC](https://discourse.nodered.org/t/change-msg-payload-from-text-to-value/65547/6 "2022-09-23T09:29:24Z")

</div>

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