cburgmer/json-path-comparison

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

yangbodong22011 opened this issue · 7 comments

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 commented

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.

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 commented

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.

@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.

glyn commented

@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...

@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.