我有下一个JSON
{
"updated": [
{
"id": "1",
"email": "api.test@test.io",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 21,
"gender": "male"
},
{
"id": "2",
"email": "api.test@test.io",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 22,
"gender": "male"
},
{
"id": "3",
"email": "api.test@test.io",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 23,
"gender": "male"
}
],
"deleted": [
{
"id": "4",
"email": "api.test@test.io",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 31,
"gender": "male"
},
{
"id": "5",
"email": "api.test@test.io",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 32,
"gender": "male"
},
{
"id": "6",
"email": "api.test@test.io",
"businessUnit": "US",
"firstName": "John",
"lastName": "Doe",
"age": 33,
"gender": "male"
}
]
}
是否可以通过其他方式而不是更改'id'字段:
是否可以像这样在“更新”和“删除”部分中更改所有“ id”文件:
答案 0 :(得分:1)
已编辑:好的,所以您想使用批量编辑,并且具有一些逻辑,可以同时增加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}]