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 inside Array return wrong results #1014

Open
milerh opened this issue Jul 2, 2024 · 0 comments
Open

Filter inside Array return wrong results #1014

milerh opened this issue Jul 2, 2024 · 0 comments

Comments

@milerh
Copy link

milerh commented Jul 2, 2024

Hi,
I have the following json:
{
"Type": "RRR",
"TypeNames": [
{
"Type": "AAA",
"Name":"Test1"
},
{
"Type" : "BBB",
"Name":"Test2"
}
]
}
I want to get the name where type="BBB"

In the following function I expect to get 1 results but I'm getting 3:
tree= the above json.

public static void testArrayCondition(String tree) {
String prop = "$.TypeNames[?(@.Type == 'BBB')].Name";
DocumentContext ctxt = JsonPath.using(TypedObjectJsonInfo.configuration).parse(tree);
JsonPathLocation listen = new JsonPathLocation(prop, ctxt);
ReadContext readCtxt = ctxt.withListeners(listen);
try {
readCtxt.read(prop);
} catch (Exception e) {
System.out.println("error" + e);
}
int numResults = listen.getCounter();
System.out.println("numResults" + numResults);
}

2024-07-02 075845

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

1 participant