Documentation of Hurl testing with nth-filter
.
#3881
Labels
documentation
Improvements or additions to documentation
nth-filter
.
#3881
Uh oh!
There was an error while loading. Please reload this page.
I am one user who has always used Hurl! This tool is very useful for external testing and is also very useful in my team.
Proposal
Even if the JSONPath results are returned as an array, scalar comparisons can be simplified by using Hurl's nth filter. Adding this as an example in the documentation would help many users solve similar issues smoothly.
Background/issues
When using JSONPath in Hurl, even unique elements are retrieved as arrays, so comparisons such as == ‘value’ can be difficult to use as is.
Also, if you try to write == [value] directly on an array, errors such as invalid predicate value may occur, making the test confusing in some cases.
Example: structure of JSON
category
== ‘fruit
and its info.code is"APPLE001"
.category
==vegetable
and its info.code isnull
In such a structure, the filter
[? (@.category == ‘fruit’)]]
will give["APPLE001"]
as an array, which is difficult to compare directly with the scalar"APPLE001"
.In practice, the following cases fail.
Solution using the
nth-filter
An nth filter exists in Hurl that takes out elements of an array as scalars, and can be used to compare them succinctly and reliably by writing
If you like, please consider adding the above to the documentation as an example of ‘Scalar comparison when the JSONPath result is an array’. It would be very helpful to have this in the official documentation, as it is a point where users can easily get tripped up.
I feel that the information is in a distant place because it was not solved by actually getting an answer from the generated AI etc. and I understood it while reading the actual source code and looking for the test sample.
Thank you!
The text was updated successfully, but these errors were encountered: