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.
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.
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.
In the meantime, we do have https://github.com/cburgmer/json-path-comparison/blob/master/regression_suite/regression_suite.yaml.
@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...