I am trying to extract a specific value returned from an API response, example below. I have extracted the entire body using response.stream.toString()
using Newman.
However I am struggling to extract the value 48.00
below when using Newman to run a postman collection.
Is there a way I could use the JSON path (x.cost) to extract the value rather than having to manipulate the string returned for the entire body?
Any help would be much appreciated.
{
"cost": 48.00,
"min": 4.000,
"max": 266.95
}
Wouldn't something simple like this work here:
const newman = require('newman');
newman.run({
collection: 'collection.json'
}).on('request', (error, args) => {
console.log(JSON.parse(args.response.stream.toString()).cost);
});
I'm taking a guess and assuming that you're using Newman as a library here.