Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add $schema property #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pke
Copy link

@pke pke commented Oct 31, 2019

VS Code supports code completion for JSON files based on JSON Schema.

Code completion in VS Code picks up a schema for any JSON file if the schema is
specified as "$schema": "<URL to schema>".

It automatically picks up certain JSON Schemas by file name (ie: package.json) and you can configure your own associations via (workspace) settings.json like this:

"json.schemas": [
  {
    "fileMatch": [
      "resume.json"
    ],
    "url": "http://json.schemastore.org/resume"
  }
]

Alternatively VS Code supports the $schema key in JSON files itself.

So in a resume.json we could add the JSON Resume schema to get code completion without touching the VS Code settings:

{
  "$schema": "http://json.schemastore.org/resume",
}

So please JSON Schema authors allow the specification of the schema in your JSON Schema like this:

{
  "properties": {
    "$schema": {
      "title": "JSON Schema to use",
      "description": "Can be a local schema or a remote one (ie from http://schemastore.org)",
      "oneOf": [
        {
          "type": "string",
          "format": "uri"
        },
        {
          "type": "string"
        }
      ]
    },
  }
}

XML had a similar feature where you could specify an XSD in the XML pre-processing tags to validate the syntax and data (to some extent) of the XML.

VS Code supports [code completion for JSON files](https://code.visualstudio.com/docs/languages/json) based on [JSON Schema](https://json-schema.org/specification.html).

Code completion in VS Code picks up a schema for any JSON file if the schema is
specified as `"$schema": "<URL to schema>"`.

It automatically picks up [certain JSON Schemas](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings) by file name (ie: `package.json`) and you can configure your own associations via (workspace) `settings.json` like this:

```json
"json.schemas": [
  {
    "fileMatch": [
      "resume.json"
    ],
    "url": "http://json.schemastore.org/resume"
  }
]
```

Alternatively VS Code supports the `$schema` key in JSON files itself.

So in a `resume.json` we could add the [JSON Resume schema](http://json.schemastore.org/resume) to get code completion without touching the VS Code settings:

```json
{
  "$schema": "http://json.schemastore.org/resume",
}
```

So please JSON Schema authors allow the specification of the schema in your JSON Schema like this:

```json
{
  "properties": {
    "$schema": {
      "title": "JSON Schema to use",
      "description": "Can be a local schema or a remote one (ie from http://schemastore.org)",
      "oneOf": [
        {
          "type": "string",
          "format": "uri"
        },
        {
          "type": "string"
        }
      ]
    },
  }
}
```

[XML](https://www.w3.org/TR/2008/REC-xml-20081126/) had a similar feature where you could specify an [XSD](https://www.w3.org/TR/xmlschema-0/) in the XML pre-processing tags to validate the syntax and data (to some extent) of the XML.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant