Hey all, I have a simple API that returns some sample JSON. I’ve gotten most of the way into visualizing the data. Each record has has a “protocols” array in which their is a transport key to indicate TCP or UDP and the actual port associated with the protocol.
I’m trying to dump all TCP ports into one table column and all UDP ports into another.
Here’s the JSON returned from the query
{
"data": {
"apps": [
{
"app_id": 27,
"app_name": "[hvlab]",
"clientless_access": false,
"host": "192.168.x.y",
"protocols": [
{
"created_at": "2023-02-27T23:52:44.665Z",
"id": 98,
"port": "22",
"service_id": 9,
"transport": "tcp",
"updated_at": "2023-02-27T23:52:44.665Z"
},
{
"created_at": "2023-02-27T23:52:44.667Z",
"id": 99,
"port": "443",
"service_id": 9,
"transport": "tcp",
"updated_at": "2023-02-27T23:52:44.667Z"
},
{
"created_at": "2023-02-27T23:52:44.668Z",
"id": 100,
"port": "2179",
"service_id": 9,
"transport": "tcp",
"updated_at": "2023-02-27T23:52:44.668Z"
},
{
"created_at": "2023-02-27T23:52:44.669Z",
"id": 101,
"port": "5985",
"service_id": 9,
"transport": "udp",
"updated_at": "2023-02-27T23:52:44.669Z"
},
{
"created_at": "2023-02-27T23:52:44.670Z",
"id": 102,
"port": "5986",
"service_id": 9,
"transport": "udp",
"updated_at": "2023-02-27T23:52:44.670Z"
}
],
},
"status": "success",
"total": 1
}
Here’s the Test I have for Visualizing this:
var table = `
<table>
<tr>
<th>App Name</th>
<th>TCP</th>
<th>UDP</th>
</tr>
{{#each response as | App|}}
<tr>
<td>{{App.app_name}}</td>
<td>"{{#each protocols}}{{#if transport}}{{tcp}}{{port}}{{#unless @last}}, {{/unless}}{{/if}}{{/each}}"</td>
<td>"{{#each protocols}}{{#if transport}}{{udp}}{{id}}{{#unless @last}}, {{/unless}}{{/if}}{{/each}}"</td>
</tr>
{{/each}}
</table>
`;
pm.visualizer.set(table, {
response: pm.response.json().data.apps
});
The problem I’m seeing is that the ports are simply duplicated in each of the port columns. How can I get just the TCP ports into the TCP column and just the UDP ports into the UDP column?