After the all-new feature called the ‘Visualizer’ was released, I had seen in the past that multiple people wanted to see their JSON/CSV data in a tabular format.
All you need to do is change the URL of the requests, send it and go the visualizer tab in the app!
Yes I lied about ‘not writing any code at all’ above, but actually you can tweak around with the delimiters and styles, or explore more around the power of the Visualizer!
WOW, great job !!!
I needed visualize any XML as a table, and it works only changing:
json: pm.response.json()
by
json: xml2Json(responseBody)
quite easy to use.
many thanks
@singhsivcan This is very useful!
I’d also like to get a specific property only.
Near the end of the script it says "In case you only want a specific property, change it here. "
Do you have an example of that?
My API response is like this, and I need to visualize only the testCase “id” values:
This is exactly what I was looking for. Huge thanks to @singhsivcan for the initial idea.
I have several API endpoints that return CSVs, and now I can see them all beautifully! It took me a bit to figure out how to get this working, so I thought I would save you some time.
Visit your collection in Postman and click on the same Tests tab.
Paste the code in.
Now MODIFY IT SLIGHTLY so that it will only run if the repsonse is a CSV:
var template = `
// etc...
`;
if (pm.response.headers.get("Content-Type").startsWith("text/csv")) {
// Provide the props as per the documentation
// https://github.com/marudhupandiyang/react-csv-to-table
let tableProps = {
data: pm.response.text(),
csvDelimiter: ',',
hasHeader: false
};
pm.visualizer.set(template, tableProps);
}
Now when any request inside this collection gets a CSV response, this code will run and display a table in the Visualizer tab. You can presumably use the same steps with the XML and JSON scripts, but I haven’t tested those.
More information about how all this works on the Postman site. And for those Googling, I originally thought I would want some way to “Preview” my CSV files. In fact, the right way to do it is with the next tab along, “Visualize.”