我有以下待验证的JSON响应。我需要验证所有数组中的所有“ createdDate” 。是否有任何简单的方法来捕获它们或在它们之间循环(因为它具有相同的对象名称,但是位于不同的数组中)并将它们放在变量中,以便根据JDBC响应中的相应值进行断言?
现在,我已使用JSON路径对每个“ createdDate”使用JSON断言,以针对数据库值进行验证。
{
"someobject1": 123,
"Array1":
[
{
"someobject2": 2,
"createdDate": "2019-03-26T20:29:44.631+0000",
"someobject3": "SCRIPT1"
},
{
"someobject4": 3,
"createdDate": "2019-03-27T20:29:44.631+0000",
"someobject5": "SCRIPT2"
}
],
"Array2":
[
{
"someobject6": 4,
"createdDate": "2019-03-28T20:29:44.631+0000",
"someobject7": "SCRIPT3"
},
{
"someobject8": 5,
"createdDate": "2019-03-29T20:29:44.631+0000",
"someobject9": "SCRIPT4"
}
]
}
答案 0 :(得分:1)
您可以使用JSON Assertion,其配置如下:
$..createdDate
["2019-03-26T20:29:44.631+0000","2019-03-27T20:29:44.631+0000","2019-03-28T20:29:44.631+0000","2019-03-29T20:29:44.631+0000"]
完整配置:
更多信息: