使用正则表达式过滤的JsonPath表达式 [英] JsonPath expression to filter using regex
本文介绍了使用正则表达式过滤的JsonPath表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在使用一个使用jayway库评估JSONpath表达式的工具. Javascript似乎无法使用.在这种情况下,如何在JSONPath中使用正则表达式.例如,在下面的示例中,我想过滤所有书名中带有单词"Sword"的书名:
We are using a tool which uses jayway library for evaluating JSONpath expression. Javascript does NOT seem to work with it. How can I use regular expression in the JSONPath in such a case. For instance, in the below example I would like to filter all book titles whose title has the word "Sword" in it:
{
"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
}
},
"expensive": 10
}
推荐答案
Jayway实现使用Ruby正则表达式运算符:
The Jayway implementation uses the Ruby regex operator:
$.store.book[?(@.title =~ /^.*Sword.*$/)]
忽略大小写:
$.store.book[?(@.title =~ /^.*sword.*$/i)]
这篇关于使用正则表达式过滤的JsonPath表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文