How to match content in json response in Postman? And visualize

Hi,

Been trying to visualize a subset of a response, but can’t seem to be able to filter it. I’m able to focus on the data i want, and I can get it output in the console, but not in the visualizer.

Thanks

Rest of the question.

Sample response, 3 mail objects.

{
    "start": 0,
    "end": 2,
    "status": "SUCCESS",
    "total": 3,
    "spam_count": 0,
    "newsletter_count": 0,
    "dataprotection_count": 3,
    "imagecontrol_count": 0,
    "dlp_count": 0,
    "compliance_count": 3,
    "mail_list": [
        {
            "id": "aad7d101d57e29d955404fdb656fbf19f1c555b11058f20c0f706dd580518784",
            "metadata": {
                "email_date_received": 1665753452481,
                "quarantine_info": {
                    "rules": [
                        "Unicode test"
                    ],
                    "direction": "inbound",
                    "quarantine_type": "CI"
                },
                "email_is_viewed": false,
                "email_is_released": true,
                "quarantine_reason": "CC",
                "email_sender": "Rob Mont (rob_mont@domain.com)",
                "service_type": "ess",
                "master_recipient": "administrator@domain1.uk",
                "user_id": 98,
                "email_envelope_sender": "rob_mont@domain.com",
                "email_released_to": "recipient",
                "email_subject": "very bad naughty",
                "email_size": 6615,
                "email_envelope_recipient": "administrator@domain1.uk"
            },
            "actions": {
                "view_subject": true,
                "delete_message": true,
                "preview_message": true,
                "release_message": true
            }
        },
        {
            "id": "623cb796e5a61237b6e58b06b8934da5698df8fdfebe6c96c61b5da4adb19e1d",
            "metadata": {
                "email_date_received": 1665753296804,
                "quarantine_info": {
                    "rules": [
                        "Unicode test"
                    ],
                    "direction": "inbound",
                    "quarantine_type": "CI"
                },
                "email_is_viewed": false,
                "email_is_released": false,
                "quarantine_reason": "CC",
                "email_sender": "Rob Mont (rob_mont@domain.com)",
                "service_type": "ess",
                "master_recipient": "demo@domain1.uk",
                "user_id": 16813960,
                "email_envelope_sender": "rob_mont@domain.com",
                "email_subject": "test dlp_trigger_word",
                "email_size": 6686,
                "email_envelope_recipient": "demo@domain1.uk"
            },
            "actions": {
                "view_subject": true,
                "delete_message": true,
                "preview_message": true,
                "release_message": true
            }
        },
        {
            "id": "bd1d3899019aa3e45087811081b4d7c237d637385b9f3fd5cf3b57243594824c",
            "metadata": {
                "email_date_received": 1665753295105,
                "quarantine_info": {
                    "rules": [
                        "Unicode test"
                    ],
                    "direction": "inbound",
                    "quarantine_type": "CI"
                },
                "email_is_viewed": false,
                "email_is_released": false,
                "quarantine_reason": "CC",
                "email_sender": "Rob Mont (rob_mont@domain.com)",
                "service_type": "ess",
                "master_recipient": "administrator@domain1.uk",
                "user_id": 98,
                "email_envelope_sender": "rob_mont@domain.com",
                "email_subject": "test dlp_trigger_word",
                "email_size": 6690,
                "email_envelope_recipient": "administrator@domain1.uk"
            },
            "actions": {
                "view_subject": true,
                "delete_message": true,
                "preview_message": true,
                "release_message": true
            }
        }
    ]
}

New code, returns just one result based on current choices, which is okay.

responseJson = JSON.parse(responseBody);
  var a=[];
  var schID;
  var list = (responseJson.mail_list).length;

console.log(list);
   for (var i = 0; i < list; i++){
        var counter = responseJson.mail_list[i];
        var subject_out = 0, type_out = 0;
        var subject_in, sender_in, recipient_in;

        //Checks the type of detection
        pm.test("Check Policy Name", function() {
            const body = pm.response.json();

                //In the match segment we can wtite our regex triggers content between the two / /
                if (pm.expect(body.mail_list[i].metadata.quarantine_info.rules).to.match(/Unicode test/)){
                    type_out = 1;        
                }else{
                    type_out = 0;
                }

            }
        );

        //Checks the subject line
        pm.test("Check Subject Trigger", function() {
            const body = pm.response.json();

                //In the match segment we can wtite our regex triggers content between the two / /
                if (pm.expect(body.mail_list[i].metadata.email_subject).to.match(/naughty/)){
                    
                    subject_in = body.mail_list[i].metadata.email_subject;
                    sender_in = body.mail_list[i].metadata.email_envelope_sender;
                    recipient_in = body.mail_list[i].metadata.email_envelope_recipient;
                    
                    subject_out = 1;
                }else{
                    subject_out = 0;
                }
            
            }
        );
        //If both type and subject are true, then return that email ID
        
        if (subject_out == 1 && type_out == 1){
            console.log("Subject: " + subject_in,"Sender: " + sender_in, "Recipient: " + recipient_in);
            schID=counter.id
            a.push(schID)
            
        }

    }

//Assigned the array with the returned IDs to the variable schID
a = JSON.stringify(a)
postman.setEnvironmentVariable("schID", a);

//Visualizer
var template = `
    <table bgcolor="#FFFFFF">
        <tr>
            <th>Subject</th>
            <th>Sender</th>
            <th>Recipient</th>
        </tr>
 
        {{#each response.mail_list}}
            <tr>
                <td>{{metadata.email_subject}}</td>
                <td>{{metadata.email_envelope_sender}}</td>
                <td>{{metadata.email_envelope_recipient}}</td>
            </tr>
        {{/each}}
    </table>
`;
 
// Set visualizer
pm.visualizer.set(template, {
    // Pass the response body parsed as JSON as `data`
    response: JSON.parse(responseBody)

});

Console result:
"Subject: very bad naughty" "Sender: rob_mont@domain.com" "Recipient: administrator@domain1.uk"

After looking around, can’t figure out how to get the html visualizer to focus just on the filtered data, instead of the whole. Looked how to filter the response into a new smaller response, but can’t get it to work.

Instead of getting the 3 results

Looking just to get the filtred value shown, matching the console

Thanks in advance.