# Output json data to html template

**URL:** <https://discourse.nodered.org/t/output-json-data-to-html-template/64344>\
**Category:** General\
**Created:** [25 June 2022 07:04 UTC](https://discourse.nodered.org/t/output-json-data-to-html-template/64344 "2022-06-25T07:04:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PateJS](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PateJS](https://discourse.nodered.org/u/PateJS)\
**Post date:** [25 June 2022 07:04 UTC](https://discourse.nodered.org/t/output-json-data-to-html-template/64344/1 "2022-06-25T07:04:10Z")

</div>

Can someone please help me get the output for Template, same output as debug shows right after http request node. found few similar posts here, but still can't get this work 🙂

```auto
[
    {
        "id": "ec5233ca1116fa70",
        "type": "http request",
        "z": "f3698a3f6c8d8f2d",
        "name": "",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "body",
        "url": "https://,
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "credentials": {},
        "x": 370,
        "y": 120,
        "wires": [
            [
                "5716c988bbe9a686",
                "2df1dbe73f69ab1d"
            ]
        ]
    },
    {
        "id": "5716c988bbe9a686",
        "type": "template",
        "z": "f3698a3f6c8d8f2d",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "<!DOCTYPE html>\n<html>\n <head>\n </head>\n <body>\n\n <h1>Hello </h1>\n {{payload.results[0].name}}\n </body>\n</html>",
        "output": "str",
        "x": 640,
        "y": 120,
        "wires": [
            [
                "f3e40b161b689c1a"
            ]
        ]
    },
    {
        "id": "f3e40b161b689c1a",
        "type": "debug",
        "z": "f3698a3f6c8d8f2d",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.results[0].name",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 120,
        "wires": []
    },
    {
        "id": "874b0adc0efdef79",
        "type": "inject",
        "z": "f3698a3f6c8d8f2d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "headers",
                "v": "{\"content-type\": \"application/json\"}",
                "vt": "json"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 120,
        "wires": [
            [
                "ec5233ca1116fa70"
            ]
        ]
    },
    {
        "id": "2df1dbe73f69ab1d",
        "type": "debug",
        "z": "f3698a3f6c8d8f2d",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.results[0].name",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 220,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [25 June 2022 08:06 UTC](https://discourse.nodered.org/t/output-json-data-to-html-template/64344/2 "2022-06-25T08:06:35Z")

</div>

Must be something with the mustache syntax accessing the deep nested values  
This [link](https://www.sitepoint.com/community/t/help-accessing-deep-level-json-in-mustache-template-solved/290780) may give you some hints

Personally i wouldnt dedicate any brain power to learn mustache ..  
just use a Change node to pick the value you want and set it as payload

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f9a06db077b23886220961d1c3c8fb201461588.png)

and in the Template use

```auto
 <body>
        <h1>Hello </h1>
        {{payload}}
 </body>

```

ps. is this for use in the Nodered Dashboard ?  
you could instead use a **ui\_template** directly that uses AngularJS instead

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [25 June 2022 08:24 UTC](https://discourse.nodered.org/t/output-json-data-to-html-template/64344/3 "2022-06-25T08:24:02Z")

</div>

Mustache template does not use square bracket notation for arrays.  
Try  
`{{payload.results.0.name}}`  
Or to loop through nested results and names arrays.

```auto
{{#payload.results}}
       {{#names}}
             {{name}}
        {{/names}}
{{/payload.results}}

```

---

<div class="post-metadata">

**Author:** ![PateJS](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PateJS](https://discourse.nodered.org/u/PateJS)\
**Post date:** [25 June 2022 09:04 UTC](https://discourse.nodered.org/t/output-json-data-to-html-template/64344/4 "2022-06-25T09:04:19Z")

</div>

I will look for these tips thank you! and I guess I need some sort of loop for this since property is nested.

---

<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:** [24 August 2022 09:04 UTC](https://discourse.nodered.org/t/output-json-data-to-html-template/64344/5 "2022-08-24T09:04:42Z")

</div>

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