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

Relative JSON Pointer specification inconsistency

Open omgmashina opened this issue 3 years ago • 4 comments

First issue: text part of section 3. Syntax does not describe [index-manipulation] which is present in ABNF.

A Relative JSON Pointer is a Unicode string in UTF-8 encoding (see RFC 8259, Section 8 [RFC8259]), comprising a non-negative integer, followed by either a '#' (%x23) character or a JSON Pointer (RFC 6901 [RFC6901]).

relative-json-pointer =  non-negative-integer [index-manipulation] <json-pointer>
relative-json-pointer =/ non-negative-integer "#"
index-manipulation    =  ("+" / "-") non-negative-integer
non-negative-integer      =  %x30 / %x31-39 *( %x30-39 )
        ; "0", or digits without a leading "0"

Second issue: one of examples (0-1#) does not comply with ABNF -- # can't be used together with [index-manipulation].

                   For example, given the JSON document:

                         {
                            "foo": ["bar", "baz"],
                            "highly": {
                               "nested": {
                                  "objects": true
                               }
                            }
                         }

     Starting from the value "baz" (inside "foo"), the following JSON
               strings evaluate to the accompanying values:

                     "0"                         "baz"
                     "1/0"                       "bar"
                     "0-1"                       "bar"
                     "2/highly/nested/objects"   true
                     "0#"                        1
                     "0-1#"                      0
                     "1#"                        "foo"

Is ABNF the ultimate truth? Should I refer to it when implementing Relative JSON Pointers? Or does ABNF require fixes? In any case, I could make a pull request with fixes, if anyone can tell me what exactly needs to be fixed.

omgmashina avatar Jan 21 '22 16:01 omgmashina

I can see this going either way. I believe the spec requires that the instance location to which # is applied must actually exist, which means that you can't just get the non-manipulated index and then add an adjustment to it. Or, rather, you would have to add the adjustment and then see if the resulting location exists, which is somewhat annoying. So I lean towards supporting 0-1#

@Relequestual I think this should be fixed in the patch release? If you agree with me here it's just that something was left out of the ABNF, so this would not be adding to the set of functionality expressed by the examples. Granted, the ABNF should be normative, but I think the intent was to support this.

handrews avatar May 20 '22 21:05 handrews

Per Slack conversation with @Relequestual I believe that there will not be a release of the Relative JSON Pointer spec alongside the immanent JSON Schema patch release, but I am advocating for (and volunteering to do the work for) an update of Relative JSON Pointer shortly afterwards.

handrews avatar May 27 '22 19:05 handrews

It looks like this has been resolved by https://github.com/json-schema-org/json-schema-spec/pull/1400 and can be closed.

notEthan avatar Jan 26 '24 08:01 notEthan

Kind of. The spec still hasn't been republished. Henry tells me there's a bit more he wants to clarify/adjust on it, but he hasn't had time.

gregsdennis avatar Jan 26 '24 09:01 gregsdennis