在 JsonPath 中按正则表达式过滤值
Filter values by regex in JsonPath
我试图找到一种使用 Jayway 的 JsonPath 通过正则表达式过滤值的方法,到目前为止,我或多或少可以做我想做的事。
我正在尝试按不以 'foo' 开头的值过滤结果。据我的正则表达式知识,它应该由 '$..book[?(@.author =~ /^[^foo]/)].author'
和
的给定 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
}
},
"expensive": 10
}
但它没有 return 任何值,尽管 none 的值是 而不是 以 'foo' 开头。我已经通过使用在线工具进行了尝试:https://jsonpath.herokuapp.com/
此外,我无法使用 Java 中编写的任何 Java 代码或过滤器或类似的代码来解决此问题。正则表达式或多或少是我唯一的选择。
有人知道如何解决这个问题吗?
干杯,
要按不以 'foo' 开头的值过滤结果,请尝试:$..book[?(@.author =~ /^(?!foo).*/i)]
正则表达式:/^(?!foo).*/i)
returns 只有不以 foo 开头的匹配(使用负先行)
我试图找到一种使用 Jayway 的 JsonPath 通过正则表达式过滤值的方法,到目前为止,我或多或少可以做我想做的事。
我正在尝试按不以 'foo' 开头的值过滤结果。据我的正则表达式知识,它应该由 '$..book[?(@.author =~ /^[^foo]/)].author'
和
{
"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
}
但它没有 return 任何值,尽管 none 的值是 而不是 以 'foo' 开头。我已经通过使用在线工具进行了尝试:https://jsonpath.herokuapp.com/
此外,我无法使用 Java 中编写的任何 Java 代码或过滤器或类似的代码来解决此问题。正则表达式或多或少是我唯一的选择。
有人知道如何解决这个问题吗?
干杯,
要按不以 'foo' 开头的值过滤结果,请尝试:$..book[?(@.author =~ /^(?!foo).*/i)]
正则表达式:/^(?!foo).*/i)
returns 只有不以 foo 开头的匹配(使用负先行)