# JSON output to html not right formatted but showing &quot;

**URL:** <https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970>\
**Category:** General\
**Created:** [20 January 2022 13:45 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970 "2022-01-20T13:45:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rednas](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@rednas](https://discourse.nodered.org/u/rednas)\
**Post date:** [20 January 2022 13:45 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970/1 "2022-01-20T13:45:14Z")

</div>

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:

`{&quot;result&quot;:&quot;off&quot;}`

What am I doing wrong and how can I fix this?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 January 2022 14:43 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970/2 "2022-01-20T14:43:53Z")

</div>

> [@rednas](#):
>
> 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...

```auto
{\"result\":\"off\"}

```

Though i am certain there is a better way. Perhaps ask on the HA forum?

---

<div class="post-metadata">

**Author:** ![rednas](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@rednas](https://discourse.nodered.org/u/rednas)\
**Post date:** [20 January 2022 14:47 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970/3 "2022-01-20T14:47:41Z")

</div>

Yes, I also did. But it is occurring inside Node-RED.  
This is what I do inside a function node:

```auto
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:

```auto
{{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...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 January 2022 14:57 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970/4 "2022-01-20T14:57:25Z")

</div>

> [@rednas](#):
>
> And subsequently I use a template node with:

Ahh - thats the missing piece of the puzzle

Try `{{{payload}}}` in template instead of `{{payload}}`

---

<div class="post-metadata">

**Author:** ![rednas](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@rednas](https://discourse.nodered.org/u/rednas)\
**Post date:** [20 January 2022 15:04 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970/5 "2022-01-20T15:04:56Z")

</div>

You are a genius 😍  
I still need to learn a lot!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 February 2022 15:05 UTC](https://discourse.nodered.org/t/json-output-to-html-not-right-formatted-but-showing-quot/56970/6 "2022-02-03T15:05:08Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
