JSON Schema editing – An introduction

      No Comments on JSON Schema editing – An introduction

You might have noticed that JSON has become a quite popular text format over the last years. Especially for everyone who is working in a Java environment. But how do you check your JSON instance documents in a convenient and standardized way like you can do for any XML file? For this purpose JSON Schema was introduced. In order to help people writing JSON schemas, the editor window in XML ValidatorBuddy provides now special syntax-coloring and entry-helpers for schema keywords as well as a built-in validator.

But how do you tell XML ValidatorBuddy that you are working on a JSON schema? Simply use the “Quick Associations” pane in the main editor window and set the “Document is JSON Schema” checkmark. From this moment on the editor knows that this JSON file should be treated as JSON schema:

Set as JSON schema

JSON Schema check-box

You will notice that the way JSON syntax-coloring works changes immediately after telling XML ValidatorBuddy that this JSON is actually a schema. All of the keywords are now green and all of the keywords are also present in the auto-completion for faster typing. Just take a look how the GeoJSON schema is displayed in the editor:

GeoJSON schema in editor

GeoJSON schema file with syntax-coloring

You can see that keywords like “properties” or “description” appear in green, while arbitrary names like “longitude” are still in red. This improves the readability of the schema in the JSON editor window a lot.

Auto-completion is a very important feature and helps tremendously on creating and editing any text-based standard. As you can see on the screenshot below, XML ValidatorBuddy provides a list of JSON schema keywords also for the auto-completion window:

auto completion for json schema

Auto-completion window for JSON schema

And how do I check my JSON instance document once the schema is ready? Simply enter the path to the JSON schema at the “JSON Schema” field of the “Quick Associations” pane when the JSON instance is the active document. Now the editor keeps a reference to the schema for this instance document. It is also possible to put a relative path here. So you can just enter the name of the schema, if both are located in the same folder. Whenever you use the “Validate against JSON Schema” command the schema content is either loaded from disk or directly taken from the editor and the validator results appear in the “Results” pane.

You can also use the JSON validator to check if the schema itself has errors. Simply use the same validate command when your JSON schema is the active document. The editor will then run the validator against the schema and you get all errors reported as usual in the Results window.

»crosslinked«

Leave a Reply