Karate - How to extract from Json Response and use as data driven data in Outline Scenario

Viewed 277

Using the below response, I want to extract the ID fields where created_by.$oid is equal to '5bf6d22a60664323c10676cf' and use the extracted Ids as data driven data for Outline Scenarios. Which is the most effective way to do so?

[ { "deleted": false, "processing": false, "id": "5ffff5b36bdfca2cb8f11135", "created_by": { "$oid": "3bf6d24a60664343c10676cf" } }, { "deleted": false, "processing": false, "id": "600070616bdfca4f2045824f", "created_by": { "$oid": "5bf6d22a60664323c10676cf" } }, { "deleted": false, "processing": false, "id": "6001907f38d61400080376f4", "created_by": { "$oid": "5bf6d22a60664323c10676cf" } } ]

1 Answers

Here you go, and please refer to the docs for how this works: https://github.com/intuit/karate#jsonpath-filters

* def fun = function(x){ return x.created_by['$oid'] == '5bf6d22a60664323c10676cf' }
* def filtered = karate.filter(response, fun)
* def ids = $filtered[*].id
* print ids
Related