hurl icon indicating copy to clipboard operation
hurl copied to clipboard

jsonpath index-selector can be negative

Open lu-zero opened this issue 6 months ago • 1 comments

As described in the specification https://www.rfc-editor.org/rfc/rfc9535#section-2.3.3.2:

A non-negative index-selector applied to an array selects an array element using a zero-based index. For example, the selector 0 selects the first, and the selector 4 selects the fifth element of a sufficiently long array. Nothing is selected, and it is not an error, if the index lies outside the range of the array. Nothing is selected from a value that is not an array.A negative index-selector counts from the array end backwards, obtaining an equivalent non-negative index-selector by adding the length of the array to the negative index. For example, the selector -1 selects the last, and the selector -2 selects the penultimate element of an array with at least two elements. As with non-negative indexes, it is not an error if such an element does not exist; this simply means that no element is selected.

Right now hurl returns an error if you try to get the last element by passing -1.

lu-zero avatar Jun 20 '25 11:06 lu-zero

Thanks @lu-zero for your issue. We will try to add it for the next release.

fabricereix avatar Jun 20 '25 12:06 fabricereix