Visualising Nested JSON as comma separated values in table

Hello,

I have a simple endpoint that returns some nested JSON in the following format:

"3809269890": {
            "item_id": "3809269890",
            "resolved_id": "3809269890",
            "given_url": "https://youtube.com/watch?v=eOVB_ewTV1I&feature=share",
            "given_title": "",
            "favorite": "0",
            "status": "1",
            "time_added": "1676736062",
            "time_updated": "1676763950",
            "time_read": "1676763949",
            "time_favorited": "0",
            "sort_id": 2,
            "resolved_title": "QUANTUMANIA POST-CREDIT SCENES BREAKDOWN (Spoilers!)",
            "resolved_url": "https://youtube.com/watch?v=eOVB_ewTV1I&feature=share",
            "excerpt": "Ant-Man and the Wasp Quantumania TWO post-credit scenes and ending explained! SPOILER WARNING: DO NOT WATCH IF YOU HAVEN'T SEEN QUANTUMANIA! To get your e-bike and free accessory today go to https://hovsco.com and use promo code ROCKSTAR1 at checkout!\n\nSubscribe to Erik's new channel, The Deep Dive,",
            "is_article": "0",
            "is_index": "0",
            "has_video": "2",
            "has_image": "1",
            "word_count": "0",
            "lang": "en",
            "tags": {
                "marvel": {
                    "item_id": "3809269890",
                    "tag": "marvel"
                },
                "movies": {
                    "item_id": "3809269890",
                    "tag": "movies"
                }
            },

I am parsing this data in Postman to put certain values into a Table using the following code:

var template = `
    <table bgcolor="#FFFFFF">
        <tr>
            <th>Unix Time Added</th>
            <th>Title</th>
            <th>Tags</th>
            <th>URL</th>
            <th>Excerpt</th>
        </tr>

        {{#each response.list}}
            <tr>
                <td>{{time_added}}</td>
                <td>{{resolved_title}}</td>
                {{#each tags}}
                    <td>{{tag}}, {{tag}}</td>
                {{/each}}
                <td>{{resolved_url}}</td>
                <td>{{excerpt}}</td>
            </tr>
        {{/each}}
    </table>
`;

// Set visualizer
pm.visualizer.set(template, {
    // Pass the response body parsed as JSON as `data`
    response: pm.response.json()
});

This creates a table as follows:

I’m trying to find a way to have the multiple tags that are nested in the JSON displayed as comma separated values in one cell in the table but I’m not sure if this is possible?

Thanks in advance for any help or tips!

I don’t know about adding the comma, but based on the example shouldn’t the rows be set using the following, otherwise its repeating the same tag.

<tr>
    <td>{{time_added}}</td>
    <td>{{resolved_title}}</td>
    <td>
        {{#each tags}}
            {{tag}}
        {{/each}}
    </td>
    <td>{{resolved_url}}</td>
    <td>{{excerpt}}</td>
</tr>

Which gives the following…

Ah yes, that does it! Thank you. Having the comma isn’t an absolutely necessity, so this answers my query - thank you again for your help!

1 Like