1

for example, I get the below list when querying from the DB [ { "a":"123", "b": "CAT" } { "a": "456", "b": null } { "a":"789", "b": "DOG" } { "a":"134", "b": null } ]

I want to remove the key and value when the value is null Expected [ { "a":"123", "b": "CAT" } { "a": "456" } { "a":"789", "b": "DOG" } { "a":"134" }

]

Please can someone help with this request, The reason I want to remove the null is the response which comes from the API ignores the null in the DB and looks like the expected, I have to match the response and the DB. Thanks in advance, Appreciate your time.

Nila
  • 11
  • 1

1 Answers1

0

This is exactly what karate.filter() is for, please search for it (and read) the docs.

And in the latest version, this short-cut will also work:

* def list = [ { "a":"123", "b": "CAT" } { "a": "456", "b": null } { "a":"789", "b": "DOG" } { "a":"134", "b": null } ]
* def list = list.filter(x => x.b != null)
* print list
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Hi Peter, Thank you for your answer, I tried your solution by updating the project to the new version, The whole object is removed including the attribute and the value for "a". I tried a different approach and it worked. Thank you once again for your support. – Nila Jun 22 '21 at 22:40