Skip to content

Instantly share code, notes, and snippets.

@carlosefonseca
Created February 24, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosefonseca/a258668c75ae3485def1376e7049592d to your computer and use it in GitHub Desktop.
Save carlosefonseca/a258668c75ae3485def1376e7049592d to your computer and use it in GitHub Desktop.
Quick and dirty Postman Visualizer for a tabled data
const res = pm.response.json();
// The list to show
const list = res["_embedded"].contacts
// Keys to ignore
const ignore = ["account_id", "deleted_at"]
// Implementation
const keys = Object.keys(list[0]).filter(x=>!ignore.includes(x))
function tostr(y) {
if (Array.isArray(y)) {
if (Object.prototype.toString.call(y[0]) != '[object Object]') {
return y.join(",")
} else {
return JSON.stringify(y)
}
} else if (Object.prototype.toString.call(y) === '[object Object]') {
return JSON.stringify(y)
} else {
return y
}
}
const res3 = list.map(x => {
return keys.map(y => tostr(x[y]))
})
var template = `
<style>
td { padding: 5px}
tt { white-space: nowrap; }
</style>
<table bgcolor="#FFFFFF" style="font-size: 6pt;">
<tr>
{{#each keys}}
<th>{{this}}</th>
{{/each}}
</tr>
{{#each response as | r | }}
{{log 'r' r}}
<tr>
{{#each r}}
<td><tt>{{this}}</tt></td>
{{/each}}
</tr>
{{/each}}
</table>
`;
pm.visualizer.set(template, {
response: res3,
keys: keys
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment