Json object: convert string to number

Debug node

payload.vars.1.value

outputs string "16"
I would like to convert that into a number, but if I use a function with

msg.payload = new Number(msg.payload.vars.1.value);
return msg;

it gives me an error. Any idea why that doesn't work?
It seems the function cannot fetch the value from the JSON object

Finally I would like a Gauge to display the value

I think there is an issue accessing number properties of an object with the . (dot) notation
Try msg.payload = Number(msg.payload.vars["1"].value)
or change the 1 key to something that starts with characters if you have access to how the original payload is constructed.

1 Like

msg.payload = Number(msg.payload.vars["1"].value)
or
msg.payload = Number(msg.payload.vars[1].value)`
worked, thanks

2 Likes

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