Create a simple text list Visualization from JSON response

So I am new to using Postman and I’m working with the Phillips Hue Bridge API on my home network. The JSON response I get from an API GET has a few nested objects that I’d like to parse out to just a name value list.
Here’s a typical response:

{
    "name": "Hue App Scene",
    "type": "GroupScene",
    "group": "1",
    "lights": [
        "1",
        "2",
        "3"
    ],
    "owner": "f6d90556-a1dc-4dc5-ba22-304633691e73",
    "recycle": false,
    "locked": false,
    "appdata": {
        "version": 1,
        "data": "97jOT_r01"
    },
    "picture": "",
    "lastupdated": "2021-08-18T13:43:05",
    "version": 2,
    "lightstates": {
        "1": {
            "on": true,
            "bri": 170,
            "ct": 464
        },
        "2": {
            "on": false,
            "bri": 91,
            "xy": [
                0.1835,
                0.2558
            ]
        },
        "3": {
            "on": false,
            "bri": 163,
            "xy": [
                0.3751,
                0.3457
            ]
        }
    }
}

This is the Visualizer output I’d like to get.

name:Hue App Scene
type:GroupScene
group:1
lights:1,2,3
owner:f6d90556-a1dc-4dc5-ba22-304633691e73
recycle:false
locked:false
appdata: version: 1, data: 97jOT_r01
picture:
lastupdated:2021-08-18T13:43:05
version:2
lightstates: 1: "on": true,"bri": 170,"ct": 464, 2: "on": false, "bri": 91, "xy": [0.1835,0.2558], 3: "on": false, "bri": 163, "xy": [0.3751,0.3457]

I can get most of it to list except for the nested objects which come out like this:
lightstates:[object Object]

Here’s the Test code I’ve tried:

var template = `
        {{#each response}}
            {{@key}}:{{this}}<br>
        {{/each}}
`;
pm.visualizer.set(template, {
    response: pm.response.json()
});

Not sure what it would take and if just using Handlebars would cut it.
Any ideas would be appreciated.
Thanks, -phil

Hi @phil366637, Welcome to the community!

The nested objects actually become complex key-value pairs. Since it is not a simple key-value pair in response, you will not be able to populate in the way mentioned.

One thing you may try is to alter the structure of response and convert all such kinds of elements before you pass it to the visualizer. Have only one level of hierarchy.

1 Like