nicojs
nicojs

Reputation: 2055

How does vscode support automatic json validation using https://schemastore.org/json/?

Should VSCode have automatic intellisense in JSON files? If so, how does it work? I know it works for well-known JSON files, like tsconfig.json, but what about other resources like stryker.conf.json?

In a number of resources online I read that it should automagically work for any schema in https://schemastore.org/json, for example: https://joshuaavalon.io/intellisense-json-yaml-vs-code. However, it doesn't seem to work for stryker.conf.json, however, it is in the schema store.

enter image description here

https://github.com/SchemaStore/schemastore/blob/e4920405e29addb278cc68dd14831700d038f937/src/api/json/catalog.json#L1081-L1086

Upvotes: 0

Views: 1236

Answers (1)

Mike Patrick
Mike Patrick

Reputation: 11006

VSCode will give intellisense for JSON whenever it has a valid schema to use, hosted at schemastore.org or anywhere else. It just needs to know what schema to use for which files.

As you noted, VSCode just "knows" what schema to use for certain well-known files, like tsconfig.json.

For other files, you can specify the schema directly in the JSON, which is what VSCode is prompting you to do in your screenshot:

Intellisense with schema specified in file

If you don't want to specify the schema in the JSON file itself, you can map file patterns to schemas in settings.json:

  "json.schemas": [
    {
      "fileMatch": ["stryker.conf.json"],
      "url": "https://raw.githubusercontent.com/stryker-mutator/stryker/master/packages/api/schema/stryker-core.json"
    }
  ]

Intellisense without schema specified in file

Upvotes: 1

Related Questions