json-schema-spec icon indicating copy to clipboard operation
json-schema-spec copied to clipboard

Alternative: Relative JSON Pointer should allow starting from after last array item

Open handrews opened this issue 2 years ago • 1 comments

This is an alternative proposal to #1235 (specifying evaluation of Relative JSON Pointer relative to JSON Pointer).

The feature that currently can't be implemented is using # to get the length of an array by applying it to - (which evaluates to the last index of the array plus one, a.k.a. its length). With what is proposed in #1235, resolving 0# against /- on the instance [0, 1, 2, 3] would result in 4.

Alternatively, the spec could be changed to allow starting with an instance location, or with the not-actually-present location of one beyond the current maximum index of an array.

Having looked at an implementation that relies on parent links being present in the de-serialized JSON structure, it would be a bit awkward to implement this in that approach. On the other hand, if you do have parent links, requiring re-evaluation from the root after resolving against a base pointer is also somewhat awkward (although note that #1235 does NOT propose requiring resolving against a base pointer, just also supporting it).

Anyway, just wanted to offer an alternate solution and note that I'm more interested in being able to use a relative pointer to get the length of an array than I am in how it is supported by the spec, or implemented by code.

handrews avatar May 21 '22 05:05 handrews

@handrews i would like to give a shot to this issue is this issue still open

vr-varad avatar Feb 27 '24 13:02 vr-varad