Empty variable returned when tried to get selected fields from json response

Viewed 28

I am trying to get subset of fields from json response but an empty variable is returned when printed it. I know similar questions have been asked but despite looking at the solutions of those I am still not able to get the intended result. I have following json. I am trying to get all the fields of this response except isbn with some value i.e. 9781449325862

{
  "isbn": "9781449325862",
  "title": "Git Pocket Guide",
  "subTitle": "A Working Introduction",
  "author": "Richard E. Silverman",
  "publish_date": "2020-06-04T08:48:39.000Z",
  "publisher": "O'Reilly Media",
  "pages": 234,
  "description": "This pocket guide is the perfect on-the-job companion to Git, the distributed version control system. It provides a compact, readable introduction to Git for new users, as well as a reference to common commands and procedures for those of you with Git exp",
  "website": "http://chimera.labs.oreilly.com/books/1230000000561/index.html"
}
  • def fun = function(x){ return x.isbn == '9781449325862' }
  • print result.isbn
  • def result = karate.filter(result, fun)
  • print result

I am getting empty result [ ]

I am expecting

{
  "title": "Git Pocket Guide",
  "subTitle": "A Working Introduction",
  "author": "Richard E. Silverman",
  "publish_date": "2020-06-04T08:48:39.000Z",
  "publisher": "O'Reilly Media",
  "pages": 234,
  "description": "This pocket guide is the perfect on-the-job companion to Git, the distributed version control system. It provides a compact, readable introduction to Git for new users, as well as a reference to common commands and procedures for those of you with Git exp",
  "website": "http://chimera.labs.oreilly.com/books/1230000000561/index.html"
}

Here we are just removing isbn field and keeping the rest same. Please help me with karate functions

1 Answers

So you just want to remove isbn ? Easy:

* remove response.isbn
Related