rednas
1
I am trying to read sensor data from Home Assistant with GET requests. I want to return the data using JSON.
I can get it to return:
{"result":"off"}
However, when I set the header content-type to application/json it shows:
{"result":"off"}
What am I doing wrong and how can I fix this?
Unfortunately, I dont know about Home Assistant but you could try escaping the quotes
e.g...
{\"result\":\"off\"}
Though i am certain there is a better way. Perhaps ask on the HA forum?
rednas
3
Yes, I also did. But it is occurring inside Node-RED.
This is what I do inside a function node:
var data={"result":msg.payload};
node.log(typeof data);
msg.payload=JSON.stringify(data);
//msg.payload=data;
return msg;
And subsequently I use a template node with:
{{payload}}
Formatted with "Mustache template" and Output As "Plain text".
This is equal for both with and without the json header specified.
So, I don't know why the difference is occurring...
Ahh - thats the missing piece of the puzzle
Try {{{payload}}}
in template instead of {{payload}}
rednas
5
You are a genius
I still need to learn a lot!
system
Closed
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.