我有下一个JSON
{
"updated": [
{
"id": "1",
"email": "[email protected]",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 21,
"gender": "male"
},
{
"id": "2",
"email": "[email protected]",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 22,
"gender": "male"
},
{
"id": "3",
"email": "[email protected]",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 23,
"gender": "male"
}
],
"deleted": [
{
"id": "4",
"email": "[email protected]",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 31,
"gender": "male"
},
{
"id": "5",
"email": "[email protected]",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 32,
"gender": "male"
},
{
"id": "6",
"email": "[email protected]",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 33,
"gender": "male"
}
]
}
编辑:好的,所以你想使用批量编辑,并有一些逻辑同时递增id-s。所以使用变换:https://github.com/intuit/karate#json-transforms
请注意,karate.map(x, i)
采用可选的第二个参数,为您提供循环索引。
* def data = [{}, {}, {}]
* def fun = function(x, i){ x.id = ~~(i + 1); return x }
* def payload = karate.map(data, fun)
* match payload == [{id: 1}, {id: 2}, {id: 3}]