空手道:如何根据 JSON 中的值删除动态元素?

Karate: How to remove dynamic element based on value from JSON?

我有一个要求,在下面JSON我必须删除所有id元素,

[
    {
        "id": "0a7936ed",
        "code": "test",
        "label": "test",
        "type": "sell"
    },
    {
        "id": "7bc1909b2",
        "code": "test2",
        "label": "test2",
        "type": "Buy"
    }
]

我的JSON应该如下所示,

[
    {
        "code": "test",
        "label": "test",
        "type": "sell"
    },
    {
        "code": "test2",
        "label": "test2",
        "type": "Buy"
    }
]

标准 JS 数组操作将适用于 Karate 1.0 及更高版本:

* def dest = source.map(x => { delete x.id; return x })

对于旧版本的空手道,一个提示是您可以使用 karate.forEach() 遍历任何 JS 对象键值,并且您可以编写条件逻辑来忽略 id