Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Karate, I am trying to match two json arrays which are out of order

Tags:

karate

for e.g.

* def products = [{"ProductCode":"a","UnitPrice":100.0},{ {"ProductCode":"b","UnitPrice":200.0}]

* def inventory = [{"ProductCode":"b","UnitPrice":200.0},{ {"ProductCode":"a","UnitPrice":100.0}]

* match products == inventory

This fails as the order of elements in the array are not matching. How can I tell karate to ignore the order?

like image 445
yogita potluri Avatar asked Sep 08 '25 07:09

yogita potluri


1 Answers

Please read the docs: https://github.com/intuit/karate#match-contains

* def products = [{"ProductCode":"a","UnitPrice":100.0},{"ProductCode":"b","UnitPrice":200.0}]
* def inventory = [{"ProductCode":"b","UnitPrice":200.0},{"ProductCode":"a","UnitPrice":100.0}]
* match products contains only inventory
like image 57
Peter Thomas Avatar answered Sep 11 '25 02:09

Peter Thomas