gregsdennis/Manatee.Json

Results do not match other implementations

cburgmer opened this issue · 3 comments

The following queries provide results that do not match those of other implementations of JSONPath
(compare https://cburgmer.github.io/json-path-comparison/):

  • $[-1]
    Input:

    ["first", "second", "third"]
    

    Expected output:

    ["third"]
    

    Actual output:

    []
    
  • $[1:10]
    Input:

    ["first", "second", "third"]
    

    Expected output:

    ["second", "third"]
    

    Error:

    Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
    
  • $..*
    Input:

    {"key": "value", "another key": {"complex": "string", "primitives": [0, 1]}}
    

    Expected output:

    ["string", "value", 0, 1, [0, 1], {"complex": "string", "primitives": [0, 1]}]
    

    Actual output:

    ["string", "value", 0, 1, [0, 1], {"complex": "string", "primitives": [0, 1]}, {"another key": {"complex": "string", "primitives": [0, 1]}, "key": "value"}]
    
  • $..*
    Input:

    [40, null, 42]
    

    Expected output:

    [40, null, 42]
    

    Actual output:

    [[40, null, 42], 40, null, 42]
    

For reference, the output was generated by the program in https://github.com/cburgmer/json-path-comparison/tree/master/implementations/dotNET_Manatee.Json.

Thanks for reporting this. I'll have a look. I have tests that cover the examples given in the JSON path blog post, but I'm afraid there's not any other docs or spec for it.

Okay... let's take these one at a time. I used https://jsonpath.com/ (powered by https://github.com/s3u/JSONPath) for my comparisons.

$[-1]

This is saying that I want the -1st (-1th?) index. It doesn't state that it should take the last element. To do that you want $[-1:] (note the colon). The different is that the colon indicates that we want to interpret the index value as a slice rather than an numerical index. It says, "start at the last element and continue to the end." However, an array doesn't have a -1 index.

Your syntax works for some languages (including C# with v8), but it's not valid for JSON Path. My implementation is correct.

$[1:10]

Technically, the error's not wrong, though the library should be tolerant of such cases, as it is with the -1 case. I'll fix this.

$..*

Looks like I'm returning the root object as well as the members. Goessner's post is not too specific about this. He simply states, "All members of JSON structure." I can fix this too.

Please see v12.0.2 for the fixes.