Skip to content

Commit 2c9b132

Browse files
committed
Change "id" to "$id", retain "id" as deprecated.
This addresses issue json-schema-org#20. "$id" matches "$schema" and "$ref", establishing a clear naming pattern for all keywords defined in the core specification. This also reduces confusion in the very common case where objects described by the schema have an "id" property. The current plan is to continue to allow for "id" until a migration tool can be provided.
1 parent 5340c4b commit 2c9b132

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

jsonschema-core.xml

+31-19
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,23 @@
325325
</t>
326326
</section>
327327

328-
<section title='The "id" keyword'>
328+
<section title='The "$id" keyword'>
329329
<t>
330-
The "id" keyword defines a URI for the schema,
330+
The "$id" keyword defines a URI for the schema,
331331
and the base URI that other URI references within the schema are resolved against.
332-
The "id" keyword itself is resolved against the base URI that the object as a whole appears in.
332+
The "$id" keyword itself is resolved against the base URI that the object as a whole appears in.
333333
</t>
334334
<t>
335335
If present, the value for this keyword MUST be a string, and MUST represent a valid <xref target="RFC3986">URI-reference</xref>.
336336
This value SHOULD be normalized, and SHOULD NOT be an empty fragment &lt;#&gt; or an empty string &lt;&gt;.
337337
</t>
338338
<t>
339-
The root schema of a JSON Schema document SHOULD contain an "id" keyword with an absolute-URI (containing a scheme, but no fragment).
339+
The root schema of a JSON Schema document SHOULD contain an "$id" keyword with an absolute-URI (containing a scheme, but no fragment).
340340
</t>
341341
<t>
342342
To name subschemas in a JSON Schema document,
343-
subschemas can use "id" to give themselves a document-local identifier.
344-
This form of "id" keyword MUST begin with a hash ("#") to identify it as a fragment URI reference,
343+
subschemas can use "$id" to give themselves a document-local identifier.
344+
This form of "$id" keyword MUST begin with a hash ("#") to identify it as a fragment URI reference,
345345
followed by a letter ([A-Za-z]), followed by any number of
346346
letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".").
347347
<!-- This restriction is the same one defined by XML -->
@@ -352,18 +352,18 @@
352352
<artwork>
353353
<![CDATA[
354354
{
355-
"id": "http://example.com/root.json",
355+
"$id": "http://example.com/root.json",
356356
"definitions": {
357-
"A": { "id": "#foo" },
357+
"A": { "$id": "#foo" },
358358
"B": {
359-
"id": "other.json",
359+
"$id": "other.json",
360360
"definitions": {
361-
"X": { "id": "#bar" },
362-
"Y": { "id": "t/inner.json" }
361+
"X": { "$id": "#bar" },
362+
"Y": { "$id": "t/inner.json" }
363363
}
364364
},
365365
"C": {
366-
"id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
366+
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
367367
}
368368
}
369369
}
@@ -389,10 +389,10 @@
389389
<section title="Internal references">
390390
<t>
391391
Schemas can be identified by any URI that has been given to them, including a JSON Pointer or
392-
their URI given directly by "id".
392+
their URI given directly by "$id".
393393
</t>
394394
<t>
395-
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "id".
395+
Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "$id".
396396
This is known as "Internal referencing".
397397
</t>
398398

@@ -404,14 +404,14 @@
404404
<artwork>
405405
<![CDATA[
406406
{
407-
"id": "http://example.net/root.json",
407+
"$id": "http://example.net/root.json",
408408
"items": {
409409
"type": "array",
410410
"items": { "$ref": "#item" }
411411
},
412412
"definitions": {
413413
"single": {
414-
"id": "#item",
414+
"$id": "#item",
415415
"type": "integer"
416416
},
417417
}
@@ -420,7 +420,7 @@
420420
</artwork>
421421
</figure>
422422
<t>
423-
When an implementation encounters the &lt;#/definitions/single&gt; schema, it resolves the "id" URI reference
423+
When an implementation encounters the &lt;#/definitions/single&gt; schema, it resolves the "$id" URI reference
424424
against the current base URI to form &lt;http://example.net/root.json#item&gt;.
425425
</t>
426426
<t>
@@ -436,14 +436,26 @@
436436
</t>
437437
<t>
438438
Implementations SHOULD be able to associate arbritrary URIs with an arbritrary schema and/or
439-
automatically associate a schema's "id"-given URI, depending on the trust that the the validator
439+
automatically associate a schema's "$id"-given URI, depending on the trust that the the validator
440440
has in the schema.
441441
</t>
442442
<t>
443443
A schema MAY (and likely will) have multiple URIs, but there is no way for a URI to identify more than one schema.
444444
When multiple schemas try to identify with the same URI, validators SHOULD raise an error condition.
445445
</t>
446446
</section>
447+
<section title='"id" as a deprecated form of "$id"'>
448+
<t>
449+
Previous drafts of this specification used "id" in place of "$id". Implementations
450+
SHOULD continue to support "id" unless and until it is removed in a future draft.
451+
To facilitate interoperability during the transitions, implementations supporting
452+
both keywords MUST NOT produce an error if both are present with the same value.
453+
</t>
454+
<t>
455+
The behavior when "$id" and "id" are present with different values is undefined.
456+
Implementations MAY issue a warning or error for such schemas.
457+
</t>
458+
</section>
447459
</section>
448460
</section>
449461

@@ -565,7 +577,7 @@ User-Agent: so-cool-json-schema/1.0.2 curl/7.43.0
565577
Validators MUST NOT fall into an infinite loop.
566578
</t>
567579
<t>
568-
Servers need to take care that malicious parties can't change the functionality of existing schemas by uploading a schema with an pre-existing or very similar "id".
580+
Servers need to take care that malicious parties can't change the functionality of existing schemas by uploading a schema with an pre-existing or very similar "$id".
569581
</t>
570582
<t>
571583
Individual JSON Schema vocabularies are liable to also have their own security considerations. Consult the respective specifications for more information.

schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
},
3030
"type": "object",
3131
"properties": {
32+
"$id": {
33+
"type": "string",
34+
"format": "uriref"
35+
},
3236
"id": {
37+
"description": "This keyword has been deprecated in favor of \"$id\"",
3338
"type": "string",
3439
"format": "uriref"
3540
},

0 commit comments

Comments
 (0)