Visualize nest json response in postman

I am trying to visualize a nested json response but am not able to correctly format test

this is the response

{

    "data": [
        {
            "Messages": null,
            "Family": [
                {
                    "Siblings": [
                        {
                            "Sibling": "Chris",
                        },
                        {
                            "Sibling": "Jenny",
                        }
						]
				}
			],
            "Appearance": {
                "hair": "black"
            },
            "Color": {
                "Skin": "brown"
				
            }
        },
	]
}

This is my test section

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: #ffffff;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>Sibling</th>
            <th>Hair</th>
            <th>Skin</th>
            
        </tr>
        {{#each response.data}}
        <tr>
            <td>{{Sibling}}</td>
            <td>{{Hair}}</td>
            <td>{{Skin}}</td>
        </tr>
        {{/each}}
    </table>
`;

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

The format of your JSON response doesn’t seem right.

You have two siblings under a family array.

But your hair appearance and skin colour are outside of that array.

What would happen if Jenny had blonde hair, where would that be in your response.

That doesn’t seem right, as you can’t just loop through the array which is why you are having issue targeting the elements.

I would expect the hair appearance and skin color to be underneath the sibling node alongside the name.

Are you in control of the API? As it would appear that the API needs some slight changes to the response format to make this work properly.

Otherwise, you can join both siblings name and have them in one cell alongside the hair and skin (but not sure that is what you want and it would appear that you want each sibling on separate lines, the problem is that the hair and skin aren’t directly linked to the name).

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