spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

JsonPath.read returns an empty array for an inexistent json path #51

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Perform calls to the JsonPath.read method for the cases below:

        // The json path matches an element with an empty array as value
        System.out.println(JsonPath.read("{\"data\": []}", "$.data"));

        // The json path doesn't match an element in the json source
        System.out.println(JsonPath.read("{\"data\": []}", "$..test"));

What is the expected output? What do you see instead?
Expected:
[]
null

Actual:
[]
[]

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

OS: CentOS

     <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>0.9.1</version>
        </dependency>

Please provide any additional information below.
As a consequence, one cannot easily make a distinction between a json path 
being contained (and paired with an empty array) and a json path not matching 
an element in the source.

Original issue reported on code.google.com by madalina...@gmail.com on 15 Sep 2014 at 2:09

GoogleCodeExporter commented 9 years ago
Might be related to: https://code.google.com/p/json-path/issues/detail?id=43

Original comment by madalina...@gmail.com on 15 Sep 2014 at 2:13

GoogleCodeExporter commented 9 years ago
This is correct behaviour. The path "$..test" means "give me all tests", it is 
not a definite path so it will always return an array. Try It out here 
http://jsonpath.herokuapp.com

Original comment by kalle.st...@gmail.com on 18 Sep 2014 at 5:57