Hello
I have a payload which is a string that looks like this "{"id":100,"percent":22.5}". I need to get the 22.5 and convert it to a number, but not sure how to do this? The percent value can go from 0 to 100 (in this case 22.5)
Hello
I have a payload which is a string that looks like this "{"id":100,"percent":22.5}". I need to get the 22.5 and convert it to a number, but not sure how to do this? The percent value can go from 0 to 100 (in this case 22.5)
That is JSON. Where did it come from?
TLDR.
when a value is JSON, it can (SHOULD) be converted to an object so that you can simply get the property using dot notation. e.g. msg.payload.percent
As for how to access values, see the part about "copy path" in the below canned text.
There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
All good - thanks - I have converted it correctly now
Sure you do!
How does the value arrive?
Show us a screenshot of the debug message
All good - I corrected my original post - thanks for the help
There are various ways to get data into Node-red, examples are Serial and MQTT. With some at least of these imports, you can specify that the data is in Json format not a string.
If your system allows this, it's a better option than "converting" the data, either with a function node or a Json parser node.