使用 JsonPath 验证 returns 列出的特定键的值
Validate value of specific key which returns list using JsonPath
响应正文:
{
"Items":[{
"ID": 12,
"Name": "n1",
"Inactive": false
},
{
"ID": 16,
"Name": "n2",
"Inactive": false
}, ...etc
]
}
使用 JsonPath 库,我能够使用以下表达式获取特定元素(例如,"Inactive")的所有值的列表。
'$.. 无效' ---> [false, false,..etc]
但是,我不确定如何使用 JsonPathAssert 应用匹配器来断言上述列表,以便它只包含 'false'.
我正在使用 Java,JsonPath。有人可以帮我吗?
经过一些研究,我能够断言列表 - 它应该只包含 'false',如下所述。
org.hamcrest.MatcherAssert.assertThat(actualJson.toString(), JsonPathMatchers.hasJsonPath("$..Inactive", Matchers.everyItem(Matchers.equalTo(false))));
响应正文:
{
"Items":[{
"ID": 12,
"Name": "n1",
"Inactive": false
},
{
"ID": 16,
"Name": "n2",
"Inactive": false
}, ...etc
]
}
使用 JsonPath 库,我能够使用以下表达式获取特定元素(例如,"Inactive")的所有值的列表。 '$.. 无效' ---> [false, false,..etc]
但是,我不确定如何使用 JsonPathAssert 应用匹配器来断言上述列表,以便它只包含 'false'.
我正在使用 Java,JsonPath。有人可以帮我吗?
经过一些研究,我能够断言列表 - 它应该只包含 'false',如下所述。
org.hamcrest.MatcherAssert.assertThat(actualJson.toString(), JsonPathMatchers.hasJsonPath("$..Inactive", Matchers.everyItem(Matchers.equalTo(false))));