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

JsonPath folds list of lists of something to list of something #36

Closed
GoogleCodeExporter opened this issue Sep 22, 2015 · 1 comment
Closed

Comments

@GoogleCodeExporter
Copy link

Json Document Example:
{ "arrayOfObjectsAndArrays" : [ { "k" : ["json"] }, { "k":["path"] }, { "k" : 
["is"] }, { "k" : ["cool"] } ],
  "arrayOfObjects" : [{"k" : "json"}, {"k":"path"}, {"k" : "is"}, {"k" : "cool"}]
}


What steps will reproduce the problem?
1. Given the Json Document Example (above)
2. Given at least the v 0.8.1 of the json-path jayway implementation
3. When you use any of these json-paths: $.arrayOfObjects..k and $. 
arrayOfObjectsAndArrays..k
4. Then the result is this for both json-paths listed above:  
["json","path","is","cool"]

What is the expected output? What do you see instead?
The expected output is:  ["json","path","is","cool"] and 
[["json"],["path"],["is"],["cool"]] respectively.


What version of the product are you using? On what operating system?
The version is 0.8.1


Please provide any additional information below.

In 0.8.1 the cause of this issue is an addAll during traversal when an element 
is a list.  This addAll ends up adding the contents of the list rather than the 
list themselves into the final result.

Original issue reported on code.google.com by michelbe...@gmail.com on 18 Sep 2013 at 3:19

@GoogleCodeExporter
Copy link
Author

Fixed and will be part of 0.9.0 release. 

    @Test
    public void issue_36() {
        String json = "{\n" +
                "\n" +
                " \"arrayOfObjectsAndArrays\" : [ { \"k\" : [\"json\"] }, { \"k\":[\"path\"] }, { \"k\" : [\"is\"] }, { \"k\" : [\"cool\"] } ],\n" +
                "\n" +
                "  \"arrayOfObjects\" : [{\"k\" : \"json\"}, {\"k\":\"path\"}, {\"k\" : \"is\"}, {\"k\" : \"cool\"}]\n" +
                "\n" +
                " }";

        Object o1 = JsonPath.read(json, "$.arrayOfObjectsAndArrays..k ");
        Object o2 = JsonPath.read(json, "$.arrayOfObjects..k ");

        assertEquals("[[\"json\"],[\"path\"],[\"is\"],[\"cool\"]]", o1.toString());
        assertEquals("[\"json\",\"path\",\"is\",\"cool\"]", o2.toString());
    }

Original comment by kalle.st...@gmail.com on 18 Sep 2013 at 5:40

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant