$id in subschema and fragments

Skip to first unread message

Matt Wlazlo

Oct 12, 2018, 4:16:12 AM10/12/18
to JSON Schema
The RCF gives the following example:

"$id": "http://example.com/root.json",
"definitions": {
"A": { "$id": "#foo" },
"B": {
"$id": "other.json",
"definitions": {
"X": { "$id": "#bar" },
"Y": { "$id": "t/inner.json" }
"C": {
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"

The schemas at the following URI-encoded JSON Pointers [RFC6901] (relative to the root schema) have the following base URIs:
Why isn't http://example.com/root.json#bar included as a base URI for #/definitions/B/definitions/X?


Henry Andrews

Oct 18, 2018, 9:36:46 AM10/18/18
to JSON Schema
Because the "$id" :"#bar" (a plain-name fragment declaration) is only resolved against its immediate base, which is "$id": "other.json", producing "other.json#bar".  It does not "see" the earlier bases.

The JSON Pointer fragments are calculated differently, as they specifically state 'When an "$id" sets the base URI, the object containing that "$id" and all of its subschemas can be identified by using a JSON Pointer fragment starting from that location.  This is true even of subschemas that further change the base URI.' (note second sentence).

It's debatable as to how ideal this is, but as the current editors/authors inhereting an existing spec, this seemed to be the behavior that most people expected.

Reply all
Reply to author
0 new messages