Parsing response data

Hello! I am wondering if I can parse only certain values from my response data with a postman call. Here is an example.

I query a site and I get the below data:

    id: <id>,
    name: <name>,
    version: <version>,
    type: <type>

I only want to return the name and version. I can achieve this by grepping to jq and grabbing what I need via CLI. Is it possible to do this in postman? Thanks!!

Hey @jb3rgman

You can use pm.response.json() in the Tests tab to get the response data.

From here you can filter that down data down to show console.log(pm.response.json().name) etc.

Hey @dannydainton, Thanks for the relpy. I have added the pm.response.json() to the tests but I am unsure where to add the console.log(pm.response.json().id) to? IS that in the tests tab as well?

Hey @jb3rgman

Yep, If you add that to the Tests tab and then open the Postman Console (On the footer menu, in the bottom left of the UI) you should see the value of that id.

Your example data is quite basic and the structure of your response could be more complex so there’s potential it won’t work if it’s within an array etc.

This isn’t really going to just return that data like you would with jq the response will continue to be the same each time but you can log certain parts of in out to the console.

Ok Thanks @dannydainton. I will try that and let you know how I progress. I appreciate the guidance. — update. it did log it. I did not know I needed to go to the console to view it. So if I was going to list multiples would I quote the log output? IS an array not an option?

The example data was just to get the jist of what I was doing. My data is more complex with other fields. (Some in Arrays). I was just curious if I could use postman to return the data that I wanted instead of the entire response. Writing those JQ queries can get very time consuming!

I answered my own question. Just add another line below it for multiples