I am attempting to convert a JavaScript object created in my Node-RED flow to JSON format, but I am struggling to figure out how to do it. The object consists of an hour and minute displayed on the screen, such as "13:02". I need to see this in JSON format on the "result" screen.
{"time": "hh: mm"}
However, I am only seeing "hh:mm" on the screen and I believe it is not in JSON format.
Additionally, when I submit the URL to a client's web service and try to view the JSON result, I receive the following error: There was an error parsing JSON data
Below is the code snippet I am using:
msg.headers = {"Content-type" : "application/json"}
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
if(hour.toString().length == 1) {
var hour = '0'+hour;}
if(minute.toString().length == 1) {
var minute = '0'+minute;
}
msg.payload = hour+':'+minute;
JSON.stringify({"time": msg.payload});
return msg;
The debug message indicates that it is a string: