Visualization Nested Object

New to Visualizer

I cant seem to get this nested array to visualize

{
  "stations": [
    {
      "stationID": "44444",
      "stationNumber": "4444"
    },
    {
      "stationID": "44444",
      "stationNumber": "4444"
    }
  ]
}

I am sure there is an easy answer. But I am stuck!!

:slight_smile:

Hey @rainwave22

Welcome to the community! :star:

Something like this, added to the Tests sandbox, should do it for you if that’s the full response body:

var template = `
    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">
        <tr>
            <th>Station ID</th>
            <th>Station Number</th>
        </tr>
        
        {{#each response.stations}}
            <tr">
                <td>{{stationID}}</td>
                <td>{{stationNumber}}</td>
            </tr>
        {{/each}}
    </table>
`;

pm.visualizer.set(template, {
    response: pm.response.json()
});

I modified an example template that you can import from here:

2 Likes

Cheers Mate!!! That worked great

1 Like

@dannydainton

I have one more for you if you do not mind
Trying to parse the nested properties but I can only get as far as ID Type and name using
{{#each response.value}}

{
“value”: [
{
“id”:
“type”:
“name”:
"properties": {
** “ownerId”: **
** “scope”: **
** “displayName”: **
** “state”: “active”,**
** “createdDate”: **
** “startDate”: **
** “expirationDate”: null,**
** “endDate”: null,**
** “notificationDate”: null,**
** “primaryKey”: **
** “secondaryKey”: **
** “stateComment”: null**
}

Any thoughts

:slight_smile:

You just need to reference the properties key and then the items within it, if that’s what you mean?

As an example, taken from the previous message in the thread:

<table class="tftable" border="1">
    <tr>
        <th>State</th>
        <th>Display Name</th>
    </tr>
    
    {{#each response.value}}
        <tr>
            <td>{{properties.state}}</td>
            <td>{{properties.displayName}}</td>
        </tr>
    {{/each}}
</table>

Or you could use the {{#with}} block helper like this:

<table class="tftable" border="1">
    <tr>
        <th>State</th>
        <th>Display Name</th>
    </tr>
    
    {{#each response.value}}
        <tr>
        {{#with properties}}
            <td>{{state}}</td>
            <td>{{displayName}}</td>
        {{/with}}
        </tr>
    {{/each}}
</table>

Is that what you’re after?

KING!!

Thank you soo much

1 Like