Skip to content

Footnote: Custom JSON Schemas

Joe Snee edited this page Jan 6, 2020 · 2 revisions

Visual Studio Code allows you to define and "enforce" (the editor displays a warning, not an error if a user schema isn't adhered to) JSON schemas based on a file pattern.

Implementing these custom schemas for your DMBinder data files can be useful for a few reasons:

Requiring Certain Attributes

Custom JSON Schema Required Attributes Screenshot

You can make sure a certain attribute is always provided.

Attribute Intellisense

Custom JSON Schema Attribute Intellisense Screenshot

VS Code's Intellisense will suggest and autocomplete names of attributes so you don't have to remember what you called that one template property (provided you setup a JSON schema to match the template) and it can populate attributes with default values if a default is defined in the JSON schema.

Normalizing and Validating Attribute Values

Custom JSON Schema Enum Attribute Values Screenshot Custom JSON Schema RegEx Attribute Value Screenshot

You can constrain the value of an attribute, by a list or a regular expression (as pictured above) among other things, making your content consistent instead of needing to remember if you put a space here or uppercased a word there, you can have VS Code enforce consistency for you!

Getting Started with Custom JSON Schemas

You can get started with some examples by using the DMBinder Yeoman Generator or read up on JSON schema documentation here!

Don't forget! If you create a custom schema, you need to tell VS Code which files will use that schema (you can find more information here).