我正在尝试验证 JSON 数组中 JSON 对象的所有属性的值是否与另一个 JSON 数组中的另一个 JSON 对象超集匹配,并进行了一些调整。
因此,我尝试使用match each
,karate.jsonPath
但似乎无法实现。除了创建函数之外,还有其他更简化的解决方案吗?
例子:
假设我有这样的 JSON 数组子集:
def subSet = [{userName: "JohnSmith", firstName: "John", lastName: "Smith", grade: 6.7}, {userName: "JohnDoe", firstName: "John", lastName: "Doe", grade: 6.9}, {userName: "WillSmith", firstName: "Will", lastName: "Smith", grade: 6.5}]
JSON 的超集如下:
def superSet = [{USERNAME: "JohnSmith", FIRSTNAME: "John", LASTNAME: "Smith", GRADE: "6.7"}, {USERNAME: "BruceWayne", FIRSTNAME: "Bruce", LASTNAME: "Wayne", GRADE: "6.2"}, {USERNAME: "JohnDoe", FIRSTNAME: "John", LASTNAME: "Doe", GRADE: "6.9"}, {USERNAME: "JaneDoe", FIRSTNAME: "Jane", LASTNAME: "Doe", GRADE: "6.1"}, {USERNAME: "WillSmith", FIRSTNAME: "Will", LASTNAME: "Smith", GRADE: "6.5"}]
请注意键的大小写差异,并且键的值'grade'
是浮点数subSet
,而 是字符串superSet
。
因此,我正在尝试的是这样的:
* match each subSet contains {grade: '#? _ == karate.jsonPath(superSet, "$[?(@.FIRSTNAME == _$.firstName && @.LASTNAME == _$.lastName)]")[0].GRADE * 1'}
有没有办法在一个班轮中匹配这个?