Open GoogleCodeExporter opened 8 years ago
Hi Stefan
I have done more tests, and come to the conclusion that we have a "worst case"
scenario: Both the syntax of my query, and jsonpath have mistakes!
I was confused by the ? sign, which means FILTER. But does it filter IN, or
OUT? I now think it means FILTER OUT from the resultset.
This means that to see all the templates that are child os area with id 1, my
query should be:
"$.landed.area[(@.id = 1)].template[*]"
I have run the following battery of tests using the slightly changed json file
at the end of this comment:
The only ones that seem to return what I expect are the double negative tests
(FILTER OUT NOT equal to) ? !=
The positive tests return results shifted by one parent (e.g I don't get the
childs of area 1, I get the childs of area 2).
Grüsse
Chris
// return all templates where the area id is 0, should return nothing
//var query = "$.landed.area[(@.id = 0)].template[*]" // returns 11 and 12 --> NOT OK
// return all templates where the area id is 1, should return 11, 12
//var query = "$.landed.area[(@.id = 1)].template[*]" //returns 21 and 22 --> NOT OK
// return all templates where the area id is 2, should return 21, 22
//var query = "$.landed.area[(@.id = 2)].template[*]" //returns 31 and 32 --> NOT OK
// return all templates where the area id is 3, should return 31, 32
//var query = "$.landed.area[(@.id = 3)].template[*]" //returns nothing --> NOT OK
// Filter OUT all those where area id is 0, should return 11, 12, 21, 22, 31, 32
//var query = "$.landed.area[?(@.id = 0)].template[*]" // returns nothing --> NOT OK
// Filter OUT all those where area id is 1, should return 21, 22, 31, 32
//var query = "$.landed.area[?(@.id = 1)].template[*]" // returns 11, 12, 21, 22, 31, 32 --> NOT OK
// Filter OUT all those where area id is 2, should return 11, 12, 31, 32
//var query = "$.landed.area[?(@.id = 2)].template[*]" // returns 11, 12, 21, 22, 31, 32 --> NOT OK
// Filter OUT all those where area id is 3, should return 11, 12, 21, 22
//var query = "$.landed.area[?(@.id = 3)].template[*]" // returns 11, 12, 21, 22, 31, 32 --> NOT OK
// return all templates where the area id is NOT 0, should return 11, 12, 21, 22, 31, 32
//var query = "$.landed.area[(@.id != 0)].template[*]" // returns nothing --> NOT OK
// return all templates where the area id is NOT 1, should return 21, 22, 31, 32
//var query = "$.landed.area[(@.id != 1)].template[*]" // returns nothing --> NOT OK
// return all templates where the area id is NOT 2, should return 11, 12, 31, 32
//var query = "$.landed.area[(@.id != 2)].template[*]" // returns nothing --> NOT OK
// return all templates where the area id is NOT 3, should return 11, 12, 21, 22
//var query = "$.landed.area[(@.id != 3)].template[*]" // returns nothing --> NOT OK
// Filter OUT all those where the area id is NOT 0, should return 11, 12, 21, 22, 31, 32
//var query = "$.landed.area[?(@.id != 0)].template[*]" // returns 11, 12, 21, 22, 31, 32 --> OK
// Filter OUT all those where the area id is NOT 1, should return 21, 22, 31, 32
//var query = "$.landed.area[?(@.id != 1)].template[*]" // returns 21, 22, 31, 32 --> OK
// Filter OUT all those where the area id is NOT 2, should return 11, 22, 31, 32
//var query = "$.landed.area[?(@.id != 2)].template[*]" // returns 11, 22, 31, 32 --> OK
// Filter OUT all those where the area id is NOT 3, should return 11, 12, 21, 22
//var query = "$.landed.area[?(@.id != 3)].template[*]" // returns 11, 12, 21, 22 --> OK
//java style equals does not work either ....
//var query = "$.landed.area[(@.id == 1 )].template[*]"
{
"landed":{
"area":[
{
"id":1,
"name":"South Africa",
"template":[
{
"id":11,
"name":"DefaultOKMsg"
},
{
"id":12,
"name":"DefaultNotOKMsg"
}
]
},
{
"id":2,
"name":"Schweiz",
"template":[
{
"id":21,
"name":"DefaultOKMsg"
},
{
"id":22,
"name":"DefaultNotOKMsg"
}
]
},
{
"id":3,
"name":"Italia",
"template":[
{
"id":31,
"name":"DefaultOKMsg"
},
{
"id":32,
"name":"DefaultNotOKMsg"
}
]
}
]
}
}
Original comment by flyingsh...@gmail.com
on 10 Feb 2014 at 2:46
SOLVED!
Some more experimentation later, it turns out that my query was (as half
suspected) wrong!
In order to get the templates belonging to area with id 1, the query should be:
"$.landed.area[?(@.id == 1 )].template[*]"
or
"$.landed.area[?(@.id === 1 )].template[*]"
i.e contrary to my comment above ? means FILTER IN, and a java style equals is
required.
You can close the issue, but it would be helpful (and would have saved several
hours hacking around and hair pulling) if you could include such an example in
your documentation. e.g.
"$..book[?(@.price == 8.99)]" // returns Moby Dick
grüsse
Chris
Original comment by flyingsh...@gmail.com
on 10 Feb 2014 at 4:14
Original issue reported on code.google.com by
flyingsh...@gmail.com
on 10 Feb 2014 at 9:55