Extending JSON meta-schema

Skip to first unread message

Roy Jacobs

Mar 25, 2019, 11:45:39 AM3/25/19
to JSON Schema

Currently I believe that JSON schema allows the definition of additional properties on fields. An example could be to indicate that a property contains sensitive information, which I could indicate either with: '"sensitive": true' on the property, or perhaps by creating an 'sensitiveProperties' array.

Now, is there a way to allow validation tools to pick up this augmented JSON meta-schema so that these additional properties can also be validated/linted instead of simply ignored?

Ben Hutton (@Relequestual)

Mar 25, 2019, 11:47:31 AM3/25/19
to JSON Schema

Hi Roy,

Yes. Ajv allows you to use custom keywords: https://ajv.js.org/custom.html


If you're asking, "Can I alert all libraries / implementations of JSON Schema to use these custom keywords somehow?", then you're answer is no, not with draft-7, but YES with draft-8 (which is not yet published).


Even so, you'd still have to write the code for each language you wanted support for, to handle your keywords.




Roy Jacobs

Mar 25, 2019, 12:04:56 PM3/25/19
to JSON Schema
Hi Ben,

Thanks for the response. I had been looking at draft-08 but I couldn't find the exact terminology that is used to define this kind of thing. Could you perhaps point me in the right direction (if you might have a link to a part of the docs that mentions this, or a few of the JSON schema compliance tests that exercise this feature)?

But yes, I am fully aware that the validation would have to be custom as well, but that's to be expected. ajv's approach seems nice!

Henry Andrews

Mar 25, 2019, 11:35:30 PM3/25/19
to JSON Schema
You're looking for the "$vocabulary" keyword.  In the forthcoming draft, you can only use it to indicate things at a vocabulary granularity, and the implementation has to recognize the vocabulary and know what it means (presumably by knowing that there is an extension it can load which can process schema objects to find its own keywords).  What will this look like in practice?  We don't know yet, that's the point of publishing the draft so folks can try implementing it.

In the following draft, we hope to provide more detailed controls at keyword granularity, but trying to figure that out without any feedback on the basic approach seemed overly ambitious so we're going to see if this direction works at all first.


You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roy Jacobs

Mar 26, 2019, 4:15:16 AM3/26/19
to JSON Schema
Ah! I noticed the "$vocabulary" keyword but I was thrown off by the fact that it was only on schema level. Thanks for the details, I'll give it a go.
Reply all
Reply to author
0 new messages