# Visualize HTML content from a JSON response

**URL:** <https://community.postman.com/t/visualize-html-content-from-a-json-response/24784>\
**Category:** Help Hub\
**Tags:** visualizer\
**Created:** [June 11, 2021, 2:23pm UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784 "2021-06-11T14:23:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkloeber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tkloeber/32/8884_2.png) [@tkloeber](https://community.postman.com/u/tkloeber)\
**Post date:** [June 11, 2021, 2:23pm UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/1 "2021-06-11T14:23:33Z")

</div>

Hi folks’es,

I have a request which returns a complete HTML page inside a JSON structure, like this

```auto
{
    "Count": 1,
    "Data": [
        {
            "MJMLContent": null,
            "Html-part": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <meta name=\"viewport\" content=\"width=device-width\" />\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /
                          :
                          :
                          </html>",
             :
        }
     ],
     :
}

```

I would like to to use the Visualizer to display this HTML, but I can’t find a way of doing this.  
Is my impression correct that the _template_-parameter of the Visualizer also encloses the parameter with a html-tag?  
Following is my **Test** which results in an empty display:

```auto
var template = `
    {{response.data.Html-part}}
`
pm.visualizer.set(template, {
        response: pm.response.json().Data[0]
    }
);

```

Resulting HTML from Visualizer:

 ![Bildschirmfoto 2021-06-11 um 16.55.20](https://us1.discourse-cdn.com/getpostman/original/3X/a/f/afeb1a2e7c151b2b97804403c8337f0a93a408d4.png)

Any help/ideas much appreciated…

---

<div class="post-metadata">

**Author:** ![neilstudd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/neilstudd/32/8213_2.png) [@neilstudd](https://community.postman.com/u/neilstudd)\
**Post date:** [June 11, 2021, 3:03pm UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/2 "2021-06-11T15:03:20Z")

</div>

Hi @tkloeber,

I had a little trouble with the structure of your sample response (it seems to have some extra linebreaks/colons which aren’t valid JSON) but that’s probably just a pasting problem. I replaced it with some simpler HTML for my own testing purposes, and here’s an example which worked for me.

Note that you need to [HTML escape](https://handlebarsjs.com/guide/expressions.html#html-escaping) the content within your template by using triple-braces, to prevent it from being printed as a literal string.

```auto
var template = `
    {{#each response.Data}}
    {{{Html-part}}}
    {{/each}}
`
pm.visualizer.set(template, {
        response: pm.response.json()
    }
);

```

---

<div class="post-metadata">

**Author:** ![tkloeber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tkloeber/32/8884_2.png) [@tkloeber](https://community.postman.com/u/tkloeber)\
**Post date:** [June 11, 2021, 3:32pm UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/3 "2021-06-11T15:32:08Z")

</div>

thanx @neilstudd for your reply.  
Yes, it certainly was a copy/paste problem, I receive a valid JSON response containing a valid HTML content in one of the fields (I just didn’t want to copy the complete content, for brevity and security 😉 )

but unfortunately your solution doesn’t work for me, it still gives me an empty output, looking just like the result in my OP.

---

<div class="post-metadata">

**Author:** ![ArtWolf](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/artwolf/32/7104_2.png) [@ArtWolf](https://community.postman.com/u/ArtWolf)\
**Post date:** [June 11, 2021, 4:21pm UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/4 "2021-06-11T16:21:57Z")

</div>

Another option would be to utilize an iframe to display the HTML

```auto
var template = `<iframe srcdoc="{{response.Html-part}}"></iframe>`;

pm.visualizer.set(template, {
        response: pm.response.json().Data[0]
});

```

---

<div class="post-metadata">

**Author:** ![manish\_runapp](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@manish\_runapp](https://community.postman.com/u/manish_runapp)\
**Post date:** [June 12, 2021, 11:15am UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/5 "2021-06-12T11:15:47Z")

</div>

I am having a query on visualizer . In the JSON response which i am getting from API. I want to display a string on the basis of a value. I am using handlebar .  
How to add switch case here, for example below response  
data:{  
{“key”:1  
},{  
“key”,2  
}  
}

---

<div class="post-metadata">

**Author:** ![tkloeber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tkloeber/32/8884_2.png) [@tkloeber](https://community.postman.com/u/tkloeber)\
**Post date:** [June 14, 2021, 6:46am UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/6 "2021-06-14T06:46:46Z")

</div>

great @ArtWolf, that does the trick, thank you!

---

<div class="post-metadata">

**Author:** ![rgimatdinov](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rgimatdinov](https://community.postman.com/u/rgimatdinov)\
**Post date:** [August 30, 2021, 12:16pm UTC](https://community.postman.com/t/visualize-html-content-from-a-json-response/24784/7 "2021-08-30T12:16:54Z")

</div>

Also if anyone need to visualize several htmls from response you can use this

```auto
pm.test("Visualize emails", function () {
    var template = `
        {{#each response}}
        <iframe width="800" height="1200" align="center" srcdoc="{{body}}"></iframe><br>
        {{/each}}
    `
    pm.visualizer.set(template, {
            response: pm.response.json()
        }
    );    
});

```
