Copyright © 2023 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
This document introduces an RDF vocabulary for JSON schema definitions. This vocabulary provides a stable namespace IRI for JSON schema keywords, as well as simple axioms, defined against schema.org's meta-model. Various examples on how to use the vocabulary are also introduced, e.g. to annotate schemas with JSON-LD metadata or to embed schema annotations inside RDF graphs.
Please note that the Turtle version of the ontology can be always obtained by doing content negotiation as explained in
Appendix D of the Thing Description Recommendation. You can
include Accept: text/turtle
in the request to
obtain the Turtle version of this ontology.
This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
Validation of the document by the Working Group is expected by the end of June 2019.
This document was published by the Web of Things Working Group as an Editor's Draft.
Publication as an Editor's Draft does not imply endorsement by W3C and its Members.
This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 03 November 2023 W3C Process Document.
JSON schema is a popular schema language for JSON documents [json-schema-validation]. This vocabulary includes the main terms defined by JSON schema in order to represent schema definitions in RDF. Besides providing a stable namespace IRI for JSON schema terms, this vocabulary also includes axioms based on schema.org's meta-model. Its design favors simplicity of use over completeness.
Representing JSON schema in RDF was originally intended to be used as part of the W3C Web of Things (WoT) framework and in particular in the Thing Description model [wot-thing-description]. However, processing JSON schema in RDF is not limited to WoT. Other use cases include:
incidentally, the RDF representation of JSON schema definitions provides an alternative to the JSON hyper-schema [json-hyper-schema] for cross-references and linking. Examples are provided at the end of the document.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The fundamental WoT terminology such as Thing, Consumer, Thing Description (TD), Interaction Model, Interaction Affordance, Property, Action, Event, Protocol Binding, Servient, etc. is defined in Section 3 of the WoT Architecture specification [WOT-ARCHITECTURE].
The Thing Description terminology such as TD Information Model, TD Document, Term (Vocabulary Term), etc. is defined in Section 3 of the WoT Thing Description specification [WOT-THING-DESCRIPTION].
IRI:
https://www.w3.org/2019/wot/json-schema#ArraySchema
array
assigned to
type
in DataSchema
instances.
Sub-class of | jsonschema:DataSchema |
In the domain of | jsonschema:items jsonschema:maxItems jsonschema:minItems |
IRI:
https://www.w3.org/2019/wot/json-schema#BooleanSchema
boolean
. This subclass
is indicated by the value boolean
assigned to
type
in DataSchema
instances.
Sub-class of | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#DataSchema
IRI:
https://www.w3.org/2019/wot/json-schema#IntegerSchema
integer
. This subclass
is indicated by the value integer
assigned to
type
in DataSchema
instances.
Sub-class of | jsonschema:DataSchema |
In the domain of | jsonschema:exclusiveMaximum jsonschema:exclusiveMinimum jsonschema:maximum jsonschema:minimum jsonschema:multipleOf |
IRI:
https://www.w3.org/2019/wot/json-schema#NullSchema
null
. This subclass is
indicated by the value null
assigned to
type
in DataSchema
instances.
This Subclass describes only one acceptable value, namely
null
. It is important to note that
null
does not mean the absence of a value. It
is analogous to null
in JavaScript,
None
in Python, null
in Java and
nil
in Ruby programming languages. It can be
used as part of a oneOf
declaration, where it
is used to indicate, that the data can also be
null
.
Sub-class of | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#NumberSchema
number
. This subclass
is indicated by the value number
assigned to
type
in DataSchema
instances.
Sub-class of | jsonschema:DataSchema |
In the domain of | jsonschema:exclusiveMaximum jsonschema:exclusiveMinimum jsonschema:maximum jsonschema:minimum jsonschema:multipleOf |
IRI:
https://www.w3.org/2019/wot/json-schema#ObjectSchema
object
. This subclass
is indicated by the value object
assigned to
type
in DataSchema
instances.
Sub-class of | jsonschema:DataSchema |
In the domain of | jsonschema:properties jsonschema:required |
IRI:
https://www.w3.org/2019/wot/json-schema#StringSchema
string
. This subclass
is indicated by the value string
assigned to
type
in DataSchema
instances.
Sub-class of | jsonschema:DataSchema |
In the domain of | jsonschema:contentEncoding jsonschema:contentMediaType jsonschema:format jsonschema:maxLength jsonschema:minLength jsonschema:pattern |
IRI:
https://www.w3.org/2019/wot/json-schema#allOf
Domain includes | jsonschema:DataSchema |
Range includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#anyOf
Domain includes | jsonschema:DataSchema |
Range includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#items
Domain includes | jsonschema:ArraySchema |
Range includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#oneOf
Domain includes | jsonschema:DataSchema |
Range includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#properties
Domain includes | jsonschema:ObjectSchema |
Range includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#const
Domain includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#contentEncoding
Domain includes | jsonschema:StringSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#contentMediaType
Domain includes | jsonschema:StringSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#default
Domain includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#enum
Domain includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#exclusiveMaximum
Domain includes | jsonschema:IntegerSchema jsonschema:NumberSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#exclusiveMinimum
Domain includes | jsonschema:IntegerSchema jsonschema:NumberSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#format
Domain includes | jsonschema:StringSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#maxItems
Domain includes | jsonschema:ArraySchema |
IRI:
https://www.w3.org/2019/wot/json-schema#maxLength
Domain includes | jsonschema:StringSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#maximum
Domain includes | jsonschema:IntegerSchema jsonschema:NumberSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#minItems
Domain includes | jsonschema:ArraySchema |
IRI:
https://www.w3.org/2019/wot/json-schema#minLength
Domain includes | jsonschema:StringSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#minimum
Domain includes | jsonschema:IntegerSchema jsonschema:NumberSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#multipleOf
Domain includes | jsonschema:IntegerSchema jsonschema:NumberSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#pattern
Domain includes | jsonschema:StringSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#propertyName
Domain includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#readOnly
Domain includes | jsonschema:DataSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#required
invokeaction
,
writeproperty
) and what members will be
definitely delivered in the payload that is being received
(e.g. output of invokeaction
,
readproperty
)
Domain includes | jsonschema:ObjectSchema |
IRI:
https://www.w3.org/2019/wot/json-schema#writeOnly
Domain includes | jsonschema:DataSchema |
No AnnotationProperty found in the ontology.
The following JSON-LD context [json-ld11] can be added to JSON schema definitions to obtain an RDF representation of these definitions.
The two following examples show the equivalence between the JSON and the Turtle representations of schema definitions. These examples were taken from the collection of schemas managed by the Open Connectivity Foundation (OCF).
The value defined for the const
and enum
terms is always interpreted as a raw
JSON value, even if it is an array or an object. In RDF, it
becomes a typed literal with datatype
rdf:JSON
.
In its latest version, the JSON schema
items
term can be interpreted in two different
ways: if the value is a single schema definition, all items
in the array must then be proper instance of that schema ;
if the value is an array of schema definitions, an item in
the instance array must be an instance of the schema at the
same index in the schema array. In the latter case, the
schema array should be interpreted as an RDF list rather as
a set of statement (to preserve order). It is however not
possible to express both cases with a single JSON-LD
context. The context given in Example 1 only reflects the
former case.
JSON schema allows schemas to be defined in a
"collection" object under definitions
. This
feature is purely syntactical, hence not reflected in the
present RDF vocabulary for JSON schema. Interpreting
schemas under definitions
as JSON-LD requires
prior normalization, by substituting references in the main
schema with their definition. This normalization procedure
may be directly supported by JSON-LD processors in the
future.
The JSON Schema RDF vocabulary does not include
terms for title
and description
.
Instead, the example context maps them to widely used
Dublin Core terms with equivalent semantics.
JSON schema defines the $id
and
$ref
keywords to increase reusability but also
to define schemas in a recursive fashion. This feature is
natively supported by RDF: if schema definitions are named
resources (identified by an IRI) instead of blank nodes, they
can be referenced from anywhere on the Web.
The id
keyword (an alias for
@id
) can be used for that purpose, as shown in
the following example, taken from an OCF standard.
If the same schema definition (with the same
IRI) is used twice as the value of one of the
properties
of an object schema, it may result
in name collisions. Indeed, after transformation to RDF,
this schema will have two statements with
:propertyValue
that do not link back to the
object from which they respectively originate.
Besides IRI references between schemas, JSON hyper-schema [json-hyper-schema] allows arbitrary links to be embedded in a schema definition. An alternative to JSON hyper-schema is to use plain RDF statements or the RDF vocabulary for hypermedia controls. Examples can be found in the documentation of that vocabulary.
JSON schema definitions may specify JSON structures that
are themselves interpretable as RDF (or JSON-LD). To be able
to do so, instances of a certain schema must be given a
JSON-LD context to map JSON terms to RDF IRIs. This can be
done within a schema definition using the JSON-LD vocabulary in RDF,
and more precisely with the property
jsonld:context
.
The example above allows schema-aware agents on the Web to interpret any instance of the schema as JSON-LD by appending the context given as annotation to the instance JSON, as shown below.
Note the difference with using @context
in
the schema definition: it is used to interpret
instances as JSON-LD, while @context
would alter the way the schema itself is
interpreted.
The JSON-LD vocabulary in RDF includes terms to represent any JSON-LD context in RDF. As a result, contexts can be directly embedded in JSON schema definitions as well. The example below is a variant of Example 6 in which only a subset of schema.org's default context is embedded in the schema.
Although schema definitions are often put in separate
documents, it may be convenient to embed them in instance
data itself, as in the following example, which uses the
Smart Appliance Reference vocabulary (SAREF) [smartm2m].
This usage of the JSON schema vocabulary is similar to that
of schema:PropertyValue
and schema:PropertyValueSpecification
.
This way, it is possible to convey a JSON tree representation that does not strictly follow the RDF structure of some entity. In the following example, the temperature property expressed in SAREF terms embeds a variant of the schema of Example 3.