Using $schema
in JSON documents
#473
Replies: 3 comments 1 reply
-
IMO the main argument against defining Another limitation of this approach is that it would only work for objects. JSON Schema can represent other types at the root as well and there would still need to be some way to externally associate a JSON document with its schema.
The I think I'd rather document it as a common convention rather than something that goes in the spec. |
Beta Was this translation helpful? Give feedback.
-
One possible reflection that I have that stands against specifying |
Beta Was this translation helpful? Give feedback.
-
This shouldn't be a concern of JSON Schema itself, as it normalizes a lot of cans of worms, such as async logic being a-okay for validation, implementations willy nilly doing HTTP requests just because of a field in a JSON file and a range of behaviours in case of failure states. You really don't want this mechanics outside of IDE helper tooltips. |
Beta Was this translation helpful? Give feedback.
-
We've long held that although many editors support using
$schema
in JSON documents to indicate the schema to be used to validate that document, it's not something we can specify because we don't specify JSON. Therefore, we can't say that$schema
with a URI value in a JSON document means it should be validated by the JSON Schema represented by that URI.This makes sense, but what if we turn it around?
Instead we could say that when a JSON Schema implementation processes a JSON document that has
$schema
in it, that URI indicates the schema to use to validate it.This changes a paradigm, at least for my implementation. Currently for many implementations, the schema needs to be provided explicitly: something similar to
or
With this requirement, a user could instead just do
and the implementation would detect the schema to use.
I think this is probably the closest we could get to specifying the use of
$schema
in instances, which seems to be something that users want.(There is also some overlap with json-schema-org/json-schema-spec#1420 in that the
application/schema-instance+json
media type could also be registered to accept aschema
parameter that the implementation could honor.)This also has the nice side effect that processing a schema by its meta-schema just becomes processing a schema as any other instance.
Beta Was this translation helpful? Give feedback.
All reactions