Referencing a JSON schema in a JSON file

1,659 views
Skip to first unread message

Roy Walmsley

unread,
Mar 3, 2016, 6:25:55 AM3/3/16
to JSON Schema
Hi all,

I'm relatively new to JSON, so apologies if this has been asked before.

I have successfully developed a JSON schema, which we can apply to validate a large archive of X3D example files encoded in JSON format. I am also planning to develop related schemas to cover different versions of X3D. However, I would like to be able to add a reference, with hyperlink, to each JSON file to specify the particular schema that validates that particular file.

So far I have been unable to find any information on an approved way to do that. Has this been defined? And if so, please can you point me to it?

Thanks in anticipation,

Roy

Christoph Kappestein

unread,
Mar 3, 2016, 2:28:11 PM3/3/16
to JSON Schema
Hi Roy,

you could set the "id" of the schema to the URL pointing to your schema definition (https://tools.ietf.org/html/draft-zyp-json-schema-04#section-7.2.2).

best regards
Christoph

Roy Walmsley

unread,
Mar 4, 2016, 10:09:20 AM3/4/16
to json-...@googlegroups.com
Christoph,

Thanks for getting back to me and giving me the pointer.

The first few lines of one of our JSON example files is listed below. We currently define a top level object "X3D", and take definitions from there.

I read the section you pointed to. But, I am unclear about where to put the id string. I as assuming that I should put it first, as per the second listing. Are you aware of any tools that would read the "id" as a schema location and use that to validate the file content?

{ "X3D": {
    "@profile":"Immersive",
    "@version":"3.0",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.0.xsd",
    "head": {


  "X3D": {
    "@profile":"Immersive",
    "@version":"3.0",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.0.xsd",
    "head": {

Regards,

Roy

Roy Walmsley

unread,
Mar 11, 2016, 1:23:15 PM3/11/16
to JSON Schema
I have thought about this some more.

I note that, in the JSON schema the $schema is used to declare that a JSON fragment is actually a JSON schema, and that it must be at the root. So, I would like to propose that, if a JSON file, which is not itself a schema, wishes to reference a particular schema, it could do it in an analogous way using the keyword @schema, with the value being the url of the schema. This should also be at the root. An example would be:


Roy

Matthew Trawicki

unread,
Oct 11, 2016, 10:48:18 AM10/11/16
to JSON Schema
Hi everyone,

I also would like an official way for a JSON blob (or file in my case) to "point" at the schema which it follows. The @schema idea is probably how I'll proceed for now. Sorry Christoph, I didn't understand your suggestion either.

Thanks!

Austin William Wright

unread,
Nov 1, 2016, 6:28:47 AM11/1/16
to JSON Schema
There can't be any standard way to do this inside an application/json file, when served with that media type, because the contents of the file are defined to be opaque. Like any application/json document, what you choose will be specific to the implementation.

However, JSON Schema does specify how you can use the HTTP Link header, and how to use different media types or the "profile" media type parameter to identify which schema is associated with a JSON document. These are standard ways to identify a schema associated with the document, that will mean the same thing in any implementation in the world.

Austin.

Geraint

unread,
Nov 2, 2016, 4:54:20 AM11/2/16
to JSON Schema
I have heard (but have not confirmed personally) that some editors including Visual Studio can use "$schema" (with a "$", not a "@") to infer the schema.

Austin William Wright

unread,
Nov 4, 2016, 4:37:13 AM11/4/16
to JSON Schema
For one's own implementation this might suffice; but for sharing with others, remember to copy the value from the JSON document into the HTTP headers. Possibly also remove the keyword to prevent confusion.
Reply all
Reply to author
Forward
0 new messages