JsonPath-PHP
JsonPath-PHP copied to clipboard
Results do not match other implementations
The following queries provide results that do not match those of other implementations of JSONPath (compare https://cburgmer.github.io/json-path-comparison/):
-
[ ]
$.2
Input:{"a": "first", "2": "second", "b": "third"}
Expected output:
["second"]
Error:
Invalid JSONPath error: 'Error in JSONPath near '.2''
-
[ ]
$[0:0]
Input:["first", "second"]
Expected output:
[]
Error:
jsonpath returned false, this might indicate an error
-
[ ]
$[?(@.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": 0}, {"key": -1}, {"key": 41}, {"key": 41.9999}]
Actual output:
[{"key": 0}, {"key": -1}, {"key": 41}, {"key": 41.9999}, {"some": "value"}]
-
[ ]
$..*
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]
-
[ ]
$..*
Input:42
Expected output:
[]
Actual output:
[42]
For reference, the output was generated by the program in https://github.com/cburgmer/json-path-comparison/tree/master/implementations/PHP_galbar-jsonpath.
Hi, I just want to bump this issue. I see three different JSONPath implementations for PHP, and I wonder which one to use.
according to #43 I would like to switch to yours, but I am not sure how actively this project is maintained.
In particular, i wonder if &&
and ||
could be supported for compatibility with other implementations.
Hi @bwl21,
This repository is maintained but not actively developed. I'd love to come back when I have some time and do some improvements, but time is limited and I'm currently working on other projects in my free time.
Contributions are very welcome and I'm open to discussing improvements and reviewing PRs, as time allows. I'd suggest to open an issue about the &&
and ||
operators so we can discuss those changes there.
With regards to compatibility issues with "the standard jsonpath": This library was written when the standard didn't exist and I had to come up with the details of the various cases that were not specified in the original spec. Version 1 of this library is considered feature complete with that regard, although incremental backwards-compatible changes are very welcome.
I hope that answers your question and clarifies the current state of the library.
I managed to migrate my application to your implementation of JsonPath. Coming from https://github.com/SoftCreatR/JSONPath I had to deals the different behavirour of ==
which in your case also considers types.
I also had to change
"$..grouptypeMemberstatus.[?(@.id=={$authentry['grouptype_memberstatus_id']})].bezeichnung"),
to
"$..grouptypeMemberstatus[?(@.id == '{$authentry['grouptype_memberstatus_id']}')].bezeichnung"),
and I don't really know why.
so I guess I am now locked into your implementation :-)
As per commit https://github.com/Galbar/JsonPath-PHP/commit/b0c41b115e31fd67aa5cb98b8341ceec423d40bd I have reviewed the test cases provided in the issue and I added a test case for the issue. Some of the cases presented here were behaving how I understand they should (such as $.2
being an invalid JsonPath, as 2
is an invalid JavaScript variable name).
I will leave this issue open for documentation purposes. I have ticked the cases that I have solved and now match the expected results specified in the issue.
I am about to make a new major version release that breaks backwards compatibility. After some consideration I've gone ahead and implemented the missing "compatibility". The change can be found in https://github.com/Galbar/JsonPath-PHP/commit/f86b5465648595512d35b36936f8ed1fedabc14f.
You can find a specific test case for this issue with all cases you list in tests/Galbar/JsonPath/JsonObjectIssue37Test.php
I have published a new version that includes changes to match the test cases provided in this issue (https://github.com/Galbar/JsonPath-PHP/releases/tag/3.0).