[2.2.0-M1] Matchin partial json responses

Hello again :slight_smile:

I am struggling to find a clean way to do partial json matching. What I mean by that is that given a json reponse like

“items”: [
{“name”:“pommes”, “quantity”:10, “subtotal”:“4.90”,“skUUId”:“f7f4e113-a5cb-4bf1-bcd4-25de7d2a6694”},
{“name”:“poires”, “quantity”:4, “subtotal”:“6.20”,“skUUId”:“f76ded32-e8ad-49bf-ad9f-ab010686288f”},
{“name”:“cerises”, “quantity”:20, “subtotal”:“8.33”,“skUUId”:“6c67e8a4-8a0b-4f1f-ac0a-5902504326b2”},

I would like to be able to math that I do have 3 objects, with the following attributes :

{“name”:“pommes”, “quantity”:10}
{“name”:“poires”, “quantity”:4}
{“name”:“cerises”, “quantity”:20}

I can use jsonPath to extract the items array with jsonPath("$.items"), but then I haven’t found a way to get to an AST/ASTLike structure (at least a Seq[Map[String,Any]]) which I could filter. I tried using jsonPath("$.items[*][‘name’,‘quantity’]") but that mixes names and quantities in the same list

The best I have come up with for now is

.transform(seq => seq.map(item => JsonFilter.jMapJsonFilter.filter(item).filterKeys(matchKeys.contains)).toSet)

which does not feel right


You could have 3 distinct checks.

If all I need to do is check the values that would work but I also need to save the results to pass them to the next request