How to set up JSON Schema with VSCode
#74 · 2020-07-24 · JSON Schema, VSCodeJSON Schema is a great way to simplify writing and validating JSON files. The popular IDE Visual Studio Code has built-in support for JSON Schema definitions. It only requires a quick one-time setup.
Unfortunately, VSCode does not seem to be able to load arbitrary schemas from any URL. Instead, you have to download the schema to your computer first.
Then open the IDE settings and search for "JSON Schema".
Find "JSON: Schemas" and click on "Edit in settings.json".
The settings.json will be opened with the corresponding setting already prefilled.
The fileMatch property is a list of file name patters that should be validated against the schema.
The url property allows you to define the address of the schema.
As currently only local files seem to work, you have to point it to the right path prefixed by file:.
The following example shows how such a configuration could look like. Make sure to adjust the file pattern and path according to your needs.
{
"json.schemas": [
{
"fileMatch": [
"*.model.json"
],
"url": "file:/Users/username/Documents/some-schema.json"
}
]
}
Save the settings file and verify that the configuration works. With JSON schema configured properly, the IDE will now automatically validate JSON files that you configured accordingly. And you will also get code completion while writing JSON content like you are already used to while programming.