使用ashphy json path evaluator,以及以下JSON:
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "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
}
}
}
我希望编写一个过滤类别(例如:“小说”)并仅返回第一个元素的查询。但我好像无法弄清楚。
例如,$..book[?(@.category == "fiction")]
将返回3本书的数组,但我只想要第一本书:
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
能做到吗?明显的方法似乎是在末尾添加"[0]",但这样并不起作用。