rainwave22
(rainwave22)
February 14, 2020, 10:32pm
1
New to Visualizer
I cant seem to get this nested array to visualize
{
"stations": [
{
"stationID": "44444",
"stationNumber": "4444"
},
{
"stationID": "44444",
"stationNumber": "4444"
}
]
}
I am sure there is an easy answer. But I am stuck!!
Hey @rainwave22
Welcome to the community!
Something like this, added to the Tests
sandbox, should do it for you if that’s the full response body:
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: #87ceeb;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>Station ID</th>
<th>Station Number</th>
</tr>
{{#each response.stations}}
<tr">
<td>{{stationID}}</td>
<td>{{stationNumber}}</td>
</tr>
{{/each}}
</table>
`;
pm.visualizer.set(template, {
response: pm.response.json()
});
I modified an example template that you can import from here:
https://explore.postman.com/templates/3223/visualizer-examples
2 Likes
rainwave22
(rainwave22)
February 16, 2020, 1:08am
3
Cheers Mate!!! That worked great
1 Like
@danny-dainton
I have one more for you if you do not mind
Trying to parse the nested properties but I can only get as far as ID Type and name using
{{#each response.value}}
{
“value”: [
{
“id”:
“type”:
“name”:
“properties”: {
** “ownerId”: **
** “scope”: **
** “displayName”: **
** “state”: “active”,**
** “createdDate”: **
** “startDate”: **
** “expirationDate”: null,**
** “endDate”: null,**
** “notificationDate”: null,**
** “primaryKey”: **
** “secondaryKey”: **
** “stateComment”: null**
}
Any thoughts
You just need to reference the properties
key and then the items within it, if that’s what you mean?
As an example, taken from the previous message in the thread:
<table class="tftable" border="1">
<tr>
<th>State</th>
<th>Display Name</th>
</tr>
{{#each response.value}}
<tr>
<td>{{properties.state}}</td>
<td>{{properties.displayName}}</td>
</tr>
{{/each}}
</table>
Or you could use the {{#with}}
block helper like this:
<table class="tftable" border="1">
<tr>
<th>State</th>
<th>Display Name</th>
</tr>
{{#each response.value}}
<tr>
{{#with properties}}
<td>{{state}}</td>
<td>{{displayName}}</td>
{{/with}}
</tr>
{{/each}}
</table>
Is that what you’re after?
mramirem
(Marco Ramirez)
February 3, 2023, 6:17pm
7
hello friend danny, I want you to help me with a little problem, it happens that I can’t make a value visible.
I am attaching my Json response.
I would like to add the part marked in yellow, but I can’t.
{{#each response.result}}
{{#each data}}
<tr>
<td>{{this.dimensions}}</td>
<td>{{dimensionMap.dt.entity.os}}</td>
</tr>
{{/each}}
{{/each}}
From already thank you very much. If you help me, I’ll send you a Peruvian ceviche.
I’m not sure of the full context but you could use:
{{#each response.result}}
{{#each data}}
<tr>
<td>{{this.dimensionMap.[dt.entity.os]}}</td>
<td>{{this.dimensionMap.[App Version]}}</td>
</tr>
{{/each}}
{{/each}}
I was just messing about with some dummy example response:
1 Like
Hey @danny-dainton was wondering if you could assist me with this nested objects under “accounts” i.e. aid, account_id and the roles especially.
{
"data": [
{
"id": "123456987",
"accounts": [
{
"aid": 1234,
"account_id": "987654321",
"roles": [
"ADMIN",
"SALES"
],
"granted_by": "9632587410",
"created": "1999-99-01T00:00:00.000Z",
"updated": "1999-99-01T00:00:00.000Z",
"auth0_connections": null,
"expiration": "0001-01-01T00:00:00Z"
}
],
Looking forward to your response. Tried the solution but didnt work.