Change msg.payload from text to value

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 :slight_smile:

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:

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!

        "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": [

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?

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 :slight_smile:

To be honest, I don't really understand your question. The function itself does not show any errors, it's a simple one:
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:

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.

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 = Number(
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.

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

here is my simple test

[{"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":[]}]



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