Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to provide JSONPath test cases based on consensus results #104

Closed
yangbodong22011 opened this issue Mar 9, 2022 · 7 comments

Comments

@yangbodong22011
Copy link

First of all, thanks to the author for his wonderful contribution.

Now that we have a consensus result, is it possible to create a standard test case for JSONPath, the format might look like this:

  • source: the input JSON
  • path: JSONPath
  • result: the result after executing path
[
  {
    "source": {
      "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
        }
      },
      "expensive": 10
    },
    "cases": [
      {
        "path": "$.store.book[*].author",
        "result": [
          "Nigel Rees",
          "Evelyn Waugh",
          "Herman Melville",
          "J. R. R. Tolkien"
        ]
      },
      {
        "path": "$..author",
        "result": [
          "Nigel Rees",
          "Evelyn Waugh",
          "Herman Melville",
          "J. R. R. Tolkien"
        ]
      }
    ]
  }
]


This way any implementor of the JSONPath standard can be used to validate their own implementation, just like json-patch-tests.

If this project can already do what I describe, please let me know, thank you.

@glyn
Copy link
Collaborator

glyn commented Mar 9, 2022

Please note that the JSONPath standard will not necessarily support all cases of consensus in this project. Or, to answer the question in the title of this issue: no.

@yangbodong22011
Copy link
Author

Please note that the JSONPath standard will not necessarily support all cases of consensus in this project.

@glyn I agree

but I think test-cases based on https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base are still needed. Or the standard itself contains examples, like JSONPointer does.

@glyn
Copy link
Collaborator

glyn commented Mar 9, 2022

Agreed. Please see https://github.com/jsonpath-standard/jsonpath-compliance-test-suite, which is currently not making progress. I stopped work on this to concentrate on editing. One of the most significant hurdles to be overcome is how to cope with non-determinism in the spec (discussed in ietf-wg-jsonpath/draft-ietf-jsonpath-base#60), possibly by allowing tests to specify multiple possible results.

@yangbodong22011
Copy link
Author

@glyn Thanks for the info, I think when standards and test suites influence each other.
Maybe we can distinguish between "exact" and "fuzzy" types in the test suite result, and for "fuzzy", we sort the results and compare them.

@cburgmer
Copy link
Owner

cburgmer commented Mar 9, 2022

In the meantime, we do have https://github.com/cburgmer/json-path-comparison/blob/master/regression_suite/regression_suite.yaml.

@glyn
Copy link
Collaborator

glyn commented Mar 9, 2022

@glyn Thanks for the info, I think when standards and test suites influence each other. Maybe we can distinguish between "exact" and "fuzzy" types in the test suite result, and for "fuzzy", we sort the results and compare them.

Thanks for the suggestion. I haven't thought it through yet...

@yangbodong22011
Copy link
Author

yangbodong22011 commented Mar 9, 2022

@cburgmer Thanks for your yaml file, it's really cool, and i will close this issue.
cc @glyn Regarding the test suite, Is it welcome to add some Filter cases to it now? This project license is GLP 3.0 and my project cannot use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants