Using a custom JSON schema repository in JSONBuddy

What is a JSON schema repository (or library)? A schema repository is a collection of JSON schemas. Often, those schemas are available online. One example of a popular online schema library is https://schemastore.org. There is a collection of hundreds of schemas available and you can browse and download them. A good opportunity to learn and to see how other people are writing schema documents. It is also a good resource of specifications for many online services.

The “File | Open from JSON schema library” command in JSONBuddy provides direct access to the schema library at schemastore.org. The selection dialog allows you to easily browse and search the list of all available schemas as simply as possible.

With a single click, you can open one or multiple schemas in the JSON editor. You can also create a sample document automatically, to get a better idea about the date the schema does apply to.

How to replace the default JSON schema libray

Recently, a customer was asking me: “Is there any chance to support user-defined schema libraries? For instance, we have an API that serves up schemas. I’d like to be able to add this API to the schema library, not just schemas available from the JSON Schema Store.”

Although you can’t add a collection of schemas to the default library in the JSON editor, you can replace the repository with your own list. At a glance, you overwrite the link to the library with a link to your own repository and you need to provide JSON data with the directory of schemas using the same format.

The more technical part

To set a link to your own schema library in the JSON editor, you overwrite the Url value at the following Registry key to read the schema library catalog: HKEY_CURRENT_USER\Software\JSONBuddy\SchemastoreOrgUrl. The default value is “http://schemastore.org/api/json/catalog.json”. You can provide your own catalog as long as it is using the same format. Immediately at the next start of JSONBuddy, the tool will load the JSON file with the catalog from this address.

The JSON format of the catalog data is quite simple and basically a flat array of schema entries. A single entry follows this pattern:

    {
      "name": "JSON Feed",
      "description": "JSON schema for the JSON Feed format",
      "fileMatch": [
        "feed.json"
      ],
      "url": "https://json.schemastore.org/feed.json",
      "versions": {
        "1": "https://json.schemastore.org/feed-1.json",
        "1.1": "https://json.schemastore.org/feed.json"
      }
    }

The most important values are “name”, “url” and “fileMatch”. Where “url” points directly to the location of the JSON schema document. Take the JSON catalog at http://schemastore.org/api/json/catalog.json as a template, if you want to provide your own configuration document.