[
{
"item_id": 1,
"item_name": "bread",
},
{
"item_id": 2,
"item_name": "rice",
},
{
"item_id": 3,
"item_name": "item3",
}
]
Above is my response and how can i print all item id s on console
[
{
"item_id": 1,
"item_name": "bread",
},
{
"item_id": 2,
"item_name": "rice",
},
{
"item_id": 3,
"item_name": "item3",
}
]
Above is my response and how can i print all item id s on console
You are looking to console.log(“stuff”)
If you use console.log, you will always have to modify your script to get rid of it since it always runs. Might be better to wrap the log in something.
Use the globals to hold a debug
variable so that you can change change it from 0 and 1 depending on if you want to debug. You can setup the value in the collection, folder, or request pre-script too.
Here is what I usually use in my scripts:
const debug = pm.globals.has("debug") && (pm.globals.get("debug") == 1)
function log(msg){
debug && msg && console.log(`LOG: ${msg}`)
}
That should give you what you want if you now do this in test for the request:
const debug = pm.globals.has("debug") && (pm.globals.get("debug") == 1)
function log(msg){
debug && msg && console.log(`LOG: ${msg}`)
}
log(`Here is the json: ${JSON.stringify(pm.response.json())}`)
So, the && stuff is part of javascript and others have written about it in the community.
https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community
Look for May 13 '19 and you can find more.