Chapter 13. Extending JSON Schema
Once we accept our limits, we go beyond them.
Albert Einstein
JSON Schema is used in a wide range of disparate use cases, from UI generation to data serialization. Given its wide applicability, the JSON Schema organization cannot possibly foresee every required feature. While the vocabularies that the JSON Schema organization defines are enormously powerful, there are cases for which you need to look beyond what’s offered out of the box. You saw a glimpse of this in Chapter 12, when JSON Schema didn’t provide keywords for declaring some of the metadata we wanted for the context facet of our example data product.
In Chapter 5, you learned an important skill: how to methodically understand every JSON Schema and consult documentation for keywords and vocabularies you haven’t seen before. This chapter builds on that to show how to define custom keywords that can do almost anything you want.
There are two ways in which you can extend JSON Schema:
-
Exploit how JSON Schema collects annotations for unknown keywords (what we refer to as the simple case).
-
Properly define and publish a JSON Schema vocabulary (what we call the complex case).
Although the simple case is easy to get going, it imposes limitations on how much you can make your keywords do.
Simple Case: Unknown Keywords
When performing validation, JSON Schema implementations will silently ignore any keywords they do not recognize. This fact can be easily exploited to add arbitrary metadata ...
Get Unifying Business, Data, and Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.