Skip to content

Results do not match other implementations #5

Open
@cburgmer

Description

@cburgmer

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

  • $[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"]
    
  • $[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
    
  • $[0:3:2]
    Input:

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

    Expected output:

    ["first", "third"]
    

    Actual output:

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

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

    Expected output:

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

    Actual output:

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

    {"key": "value"}
    

    Expected output:

    ["value"]
    

    Actual output:

    {"key": "value"}
    
  • $['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"}
    
  • $.key
    Input:

    {"key": "value"}
    

    Expected output:

    ["value"]
    

    Actual output:

    {"key": "value"}
    
  • $.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
    
  • $[*]
    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)
    
  • $[*]
    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"}
    
  • $.*
    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)
    
  • $.*
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions