Currently, I am utilizing node-RED to fetch data from a robot. The debug window indicates that the data is in the format of 'msg: Object', and once copied to a notepad, it appears like this: {"topic":"","payload":27.659992218017578,"_session":{"type":"tcp","id":"0151ff7339437ec6"},"_msgid":"6a6897605a523366"}
There seems to be some confusion whether this is a JSON object or not, especially due to seeing examples with single quotes around the brackets.
To extract the "payload" value, I am attempting to use the function node within node-red for parsing. However, I keep getting an undefined response.
The script I am using is as follows:
var json = msg.payload;
var obj = JSON.parse(json);
msg.payload = console.log(obj.payload);
return msg;
Despite being new to javascript and JSON, I have made efforts to research, but most examples only involve integers for the parsing value. There is also uncertainty if the name 'payload' itself may be causing issues. Even after trying to stringify and using 'getDouble', my lack of experience has hindered any progress.
Your guidance would be greatly appreciated.