h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
565 stars 85 forks source link

Results do not match other implementations #88

Open cburgmer opened 2 years ago

cburgmer commented 2 years ago

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

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

Also do compare the draft version of the planned standard for JSONPath: https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/draft-ietf-jsonpath-base.html

tienhung2812 commented 2 years ago

Hi @cburgmer , about filter JSON Path, can you check at jsonpath_ng.ext

from jsonpath_ng.ext import parse

jsonpath_expr = parse("$[?(@.key=='value')]")

jsonpath_expr.find([
  {
    "key": "some"
  },
  {
    "key": "value"
  }
])

I found it here https://github.com/h2non/jsonpath-ng/issues/8#issuecomment-349408047

cburgmer commented 2 years ago

Ah, thanks @tienhung2812. The results look indeed... different.

jsonpath_ng.ext seems to improve things significantly. Most previously problematic queries seem to now converge towards a consensus, or the majority answer where no consensus exists, or at least stop failing. Only three queries seem to be "better" in the traditional implementation (have now started to fail or error out):

Mind you, currently those links show the traditional implementation. Two of those queries might indicate an invalid syntax.

If the community around jsonpath_ng prefers the jsonpath_ng.ext implementation, we could switch the comparison project over to that.

It would be generally possible to compare both implementations side by side in the comparison project, but that would at the same time negatively impact the consensus building, and allow this library two votes in the process, so I would not be in favour of that solution.