Comments (2)
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 [email protected]
on 10 Feb 2014 at 2:46
from jsonpath.
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 [email protected]
on 10 Feb 2014 at 4:14
from jsonpath.
Related Issues (20)
- How to reference keys?
- Keywords as properties HOT 1
- Parent operator
- Improve performance by avoiding closures (js-version)
- The php code does not consider $expr = '0' in the trace() function
- Would appreciate an code example for C#
- Escape any character in property names HOT 1
- Filter example on main JSONPATH page is incorrect
- parse object names
- Patch for /trunk/src/php/jsonpath.php
- Attempting to access a property value with an @ sign.
- jsonPath breaks when minified
- Test page showing inputs and expectations - for regression testing
- C#, Negative Phyton slice HOT 3
- filter can't contain @ or .
- Dictionary keys containing dots can't be found HOT 1
- Fail to detect wrong syntax
- json_decode stdclass compatibility
- toJSONString is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonpath.