ashphy / jsonpath-online-evaluator

JSONPath Online Evaluator
https://jsonpath.com/
MIT License
638 stars 143 forks source link

incorrect filtering? #72

Open DazzaL opened 1 year ago

DazzaL commented 1 year ago

take a sample JSON document with no arrays in it:

{
    "a": {
        "ver": "1.0.0"
    },
    "m": {
        "attr1": "test1",
        "attr2": "test2"
    },
    "d": "my document"
}

if i want to return the "m" node if say attr1 = test1 then i can do this: $.[?(@.attr1 == "test1")] which results in this seen:

[
  {
    "attr1": "test1",
    "attr2": "test2"
  }
]

this is in disagreement to the Java jayway library which when given:

        var json = JsonPath.parse("""
{
    "a": {
        "ver": "1.0.0"
    },
    "m": {
        "attr1": "test1",
        "attr2": "test2"
    },
    "d": "my document"
}
""");
        System.out.println(json.read("$.[?(@.attr1 == \"test1\")]").toString());
    }

will result in []. Jaway wants the expression to be: $.m[?(@.attr1 == \"test1\")] and if that is given, this will be returned: [{"attr1":"test1","attr2":"test2"}]

if I use $.m[?(@.attr1 == \"test1\")] in the jsonpath.com implementation though, No match is returned

is one of these implementations incorrect?

ashphy commented 1 year ago

It is incorrect behavior compared to the internet-draft of JSONPath.

However, this site uses jsonpath-plus as a parser that is not actively maintained. There is no alternative implements in nodejs, so I plan to provide it, but it will take a long time.

If you want to fix this issue, please report to the jsonpath-plus repository instead.