Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter does not apply to object fields when wildcard used #64

Open
ghost opened this issue Oct 28, 2020 · 2 comments
Open

Filter does not apply to object fields when wildcard used #64

ghost opened this issue Oct 28, 2020 · 2 comments
Milestone

Comments

@ghost
Copy link

ghost commented Oct 28, 2020

Steps to reproduce

Example JSON:

{
    "a": {
        "size": 15
    },
    "b": {
        "size": 20
    },
    "c": {
        "size": 10
    }
}

Queries:

$[?(@.size > 13)]
$.*[?(@.size > 13)]

Code:

String json = "...";  // see JSON file above
Collector collector = JsonSurferJackson.INSTANCE.collector(json);
ValueBox<Collection<Object>> first = collector.collectAll("$[?(@.size > 10)]");
ValueBox<Collection<Object>> second = collector.collectAll("$.*[?(@.size > 10)]");
collector.exec();

System.out.println(first.get());
System.out.println(second.get());

Expected

The queries $.*[?(@.size > 13)] and $[?(@.size > 13)] return an array of two items:

[ { "size": 15 }, { "size": 20 } ]

Actual

Both queries return an empty array:

[]

Note

The queries $.* and $[*] return an array of all three items:

[
    "a": {
        "size": 15
    },
    "b": {
        "size": 20
    },
    "c": {
        "size": 10
    }
]

So I would expect that a filter after a wildcard is working fine.

Environment

JsonSurfer 1.6.0 + Jackson Parser + Jackson Provider.

@wanglingsong
Copy link
Owner

wanglingsong commented Oct 28, 2020

Currently, in JsonSurfer the filter is supported for array structure only. There is not an official standard for JsonPath syntax for now. You can check the differences among JsonPath projects in this repo: https://github.com/cburgmer/json-path-comparison
So I'm not sure your expected result is "real" expected. However, if there are a huge demand on your use-case, I can implement it.

@wolfgangcolsman
Copy link

wolfgangcolsman commented Dec 5, 2020

We ran into the same issue. It would be awesome if this can be supported.

A second very similar case we encountered: to objects of the same name (instead of using an array). Seems to be a valid json too (at least jackson can process it).

"a": {
"size": 15
},
"a": {
"size": 20
}

instead of:

"a": [
{
"size": 15
},
{
"size": 20
}
]

See also cburgmer/json-path-comparison#41

@wanglingsong wanglingsong added this to the v1.7 milestone Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants