如何在空手道中只从对象数组列表中获取少量元素



我有以下json:

{
"store": { 
"book": [ { 
"category": "reference", 
"author": "Nigel Rees", 
"title": "Sayings of the Century", 
"price": 8.95 
}, { 
"category": "fiction", 
"author": "J. R. R. Tolkien", 
"title": "The Lord of the Rings", 
"isbn": "0-395-19395-8", 
"price": 22.99 
} ], 
"bicycle": { 
"color": "red", "price": 19.95 
} 
}, 
"expensive": 10 
}

我想以以下方式检索所有books'authorcategory

[ { 
"category": "reference", 
"author": "Nigel Rees" 
}, { 
"category": "fiction", 
"author": "J. R. R. Tolkien" 
} ]

请阅读文档:https://github.com/intuit/karate#json-转换

* def fun = function(x){ return { category: x.category, author: x.author } }
* def books = karate.map(response.store.book, fun)

最新更新