Created
February 24, 2020 15:14
-
-
Save carlosefonseca/a258668c75ae3485def1376e7049592d to your computer and use it in GitHub Desktop.
Quick and dirty Postman Visualizer for a tabled data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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