I was trying to find a way to filter values by regex using JsonPath from Jayway and so far I could more or less do what I want to do.
I'm trying to filter results by values which does not start with 'foo'. To my regex knowledge it should be done by '$..book[?(@.author =~ /^[^foo]/)].author' with the given JSON of
{
"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
}
but it doesn't return any values although none of the values are not starting with 'foo'. I've tried it via using the online tool: https://jsonpath.herokuapp.com/
In addition, I can't solve this problem with any Java code or Filters that would be written in Java or similar. Regex would be my more or less only choice here.
Anybody knows how to solve this problem?
Cheers,
$..book[?(@.author =~ /.*REES/i)]returns the book object so this:$..book[?(@.author =~ /.*REES/i)].authorreturns the author(s). That answer seem too simple so I'm probably missing something. If so, perhaps you could update your question to include a sample JSON document and your desired output?