I need to change an object to string but I am not getting out the desired output.
My object is like this:
I am using a function to stringify the object and strip out/replace the unwonted chars. For some reason I am not getting out the result I expect.
This is the function I am using:
var st=msg.payload;
output=JSON.stringify(st);
output=output.replace('{','');
output=output.replace('}','');
output=output.replace(',',':');
output=output.replace('"','');
msg.payload=output;
return msg;
I have tried replacing and removing the chars using the String Node and also using the above function (at present written step by step).
This is what I am getting out of the above function:
gpio17":1:"gpio13":0,"gpio27":1,"gpio22":0
This is what I would like to get out:
gpio13:0:gpio27:1:gpio17:1:gpio22:0
I am not sure why it is not working. Any help will be appreciated. Thanks.
[{"id":"cec70e3f10d1ba16","type":"function","z":"530a8a0554240fad","name":"","func":"var st=msg.payload;\noutput=JSON.stringify(st);\noutput=output.replace('{','');\noutput=output.replace('}','');\noutput=output.replace(',',':');\noutput=output.replace('\"','');\nmsg.payload=output;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":560,"wires":[["0a872df79f52613b"]]}]