joshbuddy/jsonpath

Results do not match other implementations

cburgmer opened this issue · 5 comments

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

  • $[1:10]
    Input:

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

    Expected output:

    ["second", "third"]
    

    Actual output:

    []
    
  • $['0']
    Input:

    {"0": "value"}
    

    Expected output:

    "value"
    

    Actual output:

    null
    
  • $..*
    Input:

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

    Expected output:

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

    Actual output:

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

    ["string", 42, {"key": "value"}, [0, 1]]
    

    Expected output:

    ["string", 42, {"key": "value"}, [0, 1]]
    

    Actual output:

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

    {"int": 42, "array": [0, 1], "object": {"key": "value"}, "some": "string"}
    

    Expected output:

    ["string", 42, {"key": "value"}, [0, 1]]
    

    Actual output:

    [{"int": 42, "array": [0, 1], "object": {"key": "value"}, "some": "string"}]
    

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

Interesting. I'll take a look. Some of these are definitely weird.

One thing though. This: $['0'] is not supported, yeah. :)

So. We are also returning the keys basically, not just the values in case of $..*. I think that is fine. The people who are using this library came to expect that for a long time now, so I'm not going to change the implementation to match that of others.

That would break the current usage pattern of this gem which people using it rely upon. If people would like to have other types of results, I suggest to use a different gem. I don't see this a bug. :) It's a feature of this gem to also include the keys in the results. If you happen to find an inconsistency which shows up as a bug, please report that separately. Thank you!

Thanks for your response.
Part of this issue was to gather feedback on whether this kind of qualitative comparison is helpful to the projects. I would post issues for further items that come up via this mechanism if helpful.

Absolutely please do so. And thank you for the issue and your time. 😊