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
Issue in management of alternates [q, r, ...] #114
Comments
The first issue:
In the current implementation you can only select multiple properties The second issue: In the path Hope that makes sense. |
Hi, thx for your reply.
Ok for the limitation of field alternatives. Good to know. About the use of
Here indeed book is an array and @ refers to elements of the array. But then, how would you write an expression to "select field p of any document in which there exists field q"? This was my initial intention when I wrote In
In that case @ refers to book, not to its elements. That is quite confusing compared to the [?()], isn't it? Thx in advance, I really need to make sure I understand this! ;-) Franck. |
Expressions like
That can not be done.
I agree this is confusing. Think I will remove support for |
@frmichel first case now works as you expect |
@zline Great thx! |
Don't think I will get any further with this. Current state is described below and I think it works as expected. Thoughts on this? @Test
public void issue_114_a() {
String json = "{ \"p\":{\n" +
"\"s\": { \"u\": \"su\" }, \n" +
"\"t\": { \"u\": \"tu\" }\n" +
"}}";
List<String> result = JsonPath.read(json, "$.p.['s', 't'].u");
assertThat(result).containsExactly("su","tu");
}
@Test
public void issue_114_b() {
String json = "{ \"p\": [\"valp\", \"valq\", \"valr\"] }";
List<String> result = JsonPath.read(json, "$.p[?(@ == 'valp')]");
assertThat(result).containsExactly("valp");
}
@Test
public void issue_114_c() {
String json = "{ \"p\": [\"valp\", \"valq\", \"valr\"] }";
List<String> result = JsonPath.read(json, "$.p[?(@[0] == 'valp')]");
assertThat(result).isEmpty();
}
@Test(expected = InvalidPathException.class)
public void issue_114_d() {
JsonPath.read("[]", "$..book[(@.length-1)] ");
} |
Hi again,
I have a second question.
Here is JSON document:
{ "p":{
"s": { "u": "su" },
"t": { "u": "tu" }
}}
Expression $.p.['t'].u returns "tu" => ok.
Expression $.p.['s', 't'].u returns nothing, I'd expect "su" and "tu".
Another document : { "p": ["valp", "valq", "valr"] }
Expression $.p[?(@[0] == 'valp')] returns nothing, I would expect ["valp", "valq", "valr"]
Expression $.p[?(@.length == 3)] returns nothing, I would expect ["valp", "valq", "valr"]
Am I mistaken or is there actually a bug somewhere?
Thx,
Franck.
The text was updated successfully, but these errors were encountered: