Visualize Nested JSON Response Body

Hey @michaelderekjones was wondering if you could assist me with this nested objects under “accounts” i.e. aid, account_id and the roles especially.

{
    "data": [
        {
            "id": "123456987",
            "accounts": [
                {
                    "aid": 1234,
                    "account_id": "987654321",
                    "roles": [
                        "ADMIN",
                        "SALES"
                    ],
                    "granted_by": "9632587410",
                    "created": "1999-99-01T00:00:00.000Z",
                    "updated": "1999-99-01T00:00:00.000Z",
                    "auth0_connections": null,
                    "expiration": "0001-01-01T00:00:00Z"
                }
            ],

@mission-cosmonaut-61

If there is only one “id” in your response then the following should work.

let response = pm.response.json().data // parse response

console.log(response);

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;position:sticky;top:0;}
        .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>aid</th>
            <th>account_id</th>            
        </tr>

        {{#each response}}
            {{#each accounts}}
                 <tr>
                    <td>{{aid}}</td>
                    <td>{{account_id}}</td>
                </tr>
            {{/each}}
        {{/each}}

    </table>

`;

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

If there is more than one ID, then a different approach may be needed.

1 Like

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