Defining a JSON-Schema

To get started, if you haven’t already visited the JSON-Schema site, you can do so here.  Much of what I am writing on here, is there.

In defining your schema, there are a few elements I want to highlight in the below definition that starts off any JSON-Schema file.

"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://www.365concepts.com/json-schema.json",
"type": "object",
"title": "My JSON Data File",
"required": [
"id",
"people"
],
"additionalProperties": false,

In this document, we have indicated that it will be an object.  JSON-Schema supports many attributes one of which is object that allows us to create individual properties on the objects themselves.

The #id property is largely up to you, but take note of the #schema parameter as this is the specification that are binding to that outlines what you can and can’t do within it.

From there you have the standard title and then we get into defining properties that are required for this particular schema to work.  The required keyword, takes an array of property names that if are not present in the json while when bound to the schema, will fail.

Lastly, the additionalProperties property is a cool little extension that tells the schema to not allow the user to add their own properties (perhaps for metadata reasons).  This is not false by default, so if you want to enforce this rule, you will need to explicitly state it.

Post A Reply

%d bloggers like this: