Results do not match other implementations
cburgmer opened this issue · 10 comments
The following queries provide results that do not match those of other implementations of JSONPath
(compare https://cburgmer.github.io/json-path-comparison/):
-
$["key"]
Input:{"key": "value"}
Expected output:
["value"]
Actual output:
[]
-
$[?(@['key']==42)]
Input:[{"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"some": "value"}]
Expected output:
[{"key": 42}]
Error:
wrong symbol '=' at 12
-
$[?(@.key=="some.value")]
Input:[{"key": "some"}, {"key": "value"}, {"key": "some.value"}]
Expected output:
[{"key": "some.value"}]
Error:
wrong request: wrong request: ?(@.key=="some.value")
For reference, the output was generated by the program in https://github.com/cburgmer/json-path-comparison/tree/master/implementations/Golang_github.com-spyzhov-ajson.
I've filed those on quite a few projects. Let me know if this is helpful. Feedback is welcome.
Thanks! It's really very helpful. I'll take care of this, asap.
A couple of weeks ago I implement big pack of tests for json decode, if you need it. https://github.com/spyzhov/ajson/blob/master/decode_test.go#L787-L2875
I might have a look at the test suite, it does seem though that a lot of them are also checking for valid JSON. That's taken for granted and is not part of checks.
I have taken the time to go through all the other implementations' issue tracker, to find issues filed by users. I hope this already gives us a good overview of frequent/likely errors.
Sorry, but can you please fix test suite and run again?
https://github.com/cburgmer/json-path-comparison/blob/Golang_github.com-spyzhov-ajson/implementations/Golang_github.com-spyzhov-ajson/main.go#L27
Instead of var results []interface{}
write results := make([]interface{}, 0)
Or you can simplify code, like: results, err := ArrayNode("", nodes).Unpack()
Ah, thanks for looking into this. I've updated the findings above.
Using the ArrayNode way directly gave me a panic, so I went with the make option.
Those look good, but it seems there have been regressions? See https://github.com/cburgmer/json-path-comparison/blob/master/bug_reports/Golang_github.com-spyzhov-ajson.md
Ah, thanks a lot! Yes, I tried to fix some issues, but seems to do worth. Will fix it soon.
If you think it helps you can use https://github.com/cburgmer/json-path-comparison/blob/master/regression_suite/regression_suite.yaml as a regression suite. This will be updated when new queries are added, or a consensus emerges, or changes.