Giter Club home page Giter Club logo

Comments (2)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 29, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 29, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.