JSONPath.sh icon indicating copy to clipboard operation
JSONPath.sh copied to clipboard

Results do not match other implementations

Open cburgmer opened this issue 6 years ago • 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/):

  • [x] $[1:10] Input:

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

    Expected output:

    ["second", "third"]
    

    Error:

    sed: bad regex '\[(([0-9]+|"[^"]+")[],]){9999}(.*)': Invalid contents of {}
    No JSON object could be decoded
    
  • [ ] $[-1:] Input:

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

    Expected output:

    ["third"]
    

    Actual output:

    ["first", "second", "third"]
    
  • [x] $[1:] Input:

    ["first", "second", "third", "forth", "fifth"]
    

    Expected output:

    ["second", "third", "forth", "fifth"]
    

    Error:

    sed: bad regex '\[(([0-9]+|"[^"]+")[],]){9999}(.*)': Invalid contents of {}
    No JSON object could be decoded
    
  • [x] $[0:3:2] Input:

    ["first", "second", "third", "forth", "fifth"]
    

    Expected output:

    ["first", "third"]
    

    Actual output:

    ["first", "second", "third", "forth", "fifth"]
    
  • [x] $[0:3:1] Input:

    ["first", "second", "third", "forth", "fifth"]
    

    Expected output:

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

    Actual output:

    ["first", "second", "third", "forth", "fifth"]
    
  • [x] $['key'] Input:

    {"key": "value"}
    

    Expected output:

    ["value"]
    

    Actual output:

    {"key": "value"}
    
  • [x] $['key','another'] Input:

    {"key": "value", "another": "entry"}
    

    Expected output:

    ["value", "entry"]
    

    Actual output:

    {"another": "entry", "key": "value"}
    
  • [ ] $['0'] Input:

    {"0": "value"}
    

    Expected output:

    ["value"]
    

    Error:

    sed: bad regex '\[(([0-9]+|"[^"]+")[],]){9999}(.*)': Invalid contents of {}
    No JSON object could be decoded
    
  • [ ] $['special:"chars'] Input:

    {"special:\"chars": "value"}
    

    Expected output:

    ["value"]
    

    Error:

    sed: bad regex '\[(([0-9]+|"[^"]+")[],]){9999}(.*)': Invalid contents of {}
    No JSON object could be decoded
    
  • [ ] $['*'] Input:

    {"*": "value"}
    

    Expected output:

    ["value"]
    

    Actual output:

    {"*": "value"}
    
  • [x] $.key Input:

    {"key": "value"}
    

    Expected output:

    ["value"]
    

    Actual output:

    {"key": "value"}
    
  • [x] $.key Input:

    {"key": ["first", "second"]}
    

    Expected output:

    [["first", "second"]]
    

    Actual output:

    ["first", "second"]
    
  • [ ] $.key Input:

    {"key": null}
    

    Expected output:

    [null]
    

    Actual output:

    {"key": null}
    
  • [ ] $..key Input:

    {"object": {"key": "value", "array": [{"key": "something"}, {"key": {"key": "russian dolls"}}]}, "key": "top"}
    

    Expected output:

    ["top", "value", "something", {"key": "russian dolls"}, "russian dolls"]
    

    Actual output:

    {"key": "top", "object": {"array": [{"key": "something"}, {"key": {"key": "russian dolls"}}], "key": "value"}}
    
  • [ ] $.store..price Input:

    {"store": {"book": [{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99}], "bicycle": {"color": "red", "price": 19.95}}}
    

    Expected output:

    [8.95, 12.99, 8.99, 22.99, 19.95]
    

    Actual output:

    {"bicycle": {"price": 19.95}, "book": [{"price": 8.95}, {"price": 12.99}, {"price": 8.99}, {"price": 22.99}]}
    
  • [ ] $ Input:

    {"key": "value", "another key": {"complex": ["a", 1]}}
    

    Expected output:

    [{"another key": {"complex": ["a", 1]}, "key": "value"}]
    

    Error:

    sed: bad regex '\[(([0-9]+|"[^"]+")[],]){9999}(.*)': Invalid contents of {}
    No JSON object could be decoded
    
  • [x] $[*] Input:

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

    Expected output:

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

    Error:

    Extra data: line 4 column 6 - line 12 column 1 (char 28 - 94)
    
  • [x] $[*] Input:

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

    Expected output:

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

    Actual output:

    {"array": [0, 1], "int": 42, "object": {"key": "value"}, "some": "string"}
    
  • [x] $.* Input:

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

    Expected output:

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

    Error:

    Extra data: line 4 column 6 - line 12 column 1 (char 28 - 94)
    
  • [x] $.* Input:

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

    Expected output:

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

    Actual output:

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

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

cburgmer avatar Jul 15 '19 21:07 cburgmer

Hey, opened a bunch of those with other projects as well. Special here is that I had to resort to Docker, as I have issues running it on OS X, will follow up with issue here. Docker is not feasible right now for maintaining the comparison project with >10 implementations and >40 queries, so the comparison against your Bash implementation is on a branch for now.

cburgmer avatar Jul 15 '19 21:07 cburgmer

Thanks for reviewing. I do however see two items marked done here as still failing:

  • https://cburgmer.github.io/json-path-comparison/#key_bracket_notation_with_star_literal
  • https://cburgmer.github.io/json-path-comparison/#key_bracket_notation_with_number

cburgmer avatar Jan 31 '20 08:01 cburgmer

Hi! I did quite a bit of work on this over the weekend and fixed a lot of little bugs. I need to fix the json outputter for a couple of your tests which I'll get back to when I find some time again :)

Note to self:

echo '["string", 42, {"key": "value"}, [0, 1]]' | ../../JSONPath.sh '$[*]' -j | python -m json.tool
Extra data: line 4 column 6 (char 28)

I like your comparison table and thanks for your great work!

mclarkson avatar Feb 02 '20 22:02 mclarkson