How do I configure VS Code to enable code completion on .json files (jsonschema support)?

前端 未结 3 1946
梦毁少年i
梦毁少年i 2021-02-12 15:20

In the Visual Stuido Code demo minute 28:57-29:20 and 30:20-31:10, some cool JSON code completion is shown.

Where and how do I add a schema for my JSON files to a projec

3条回答
  •  深忆病人
    2021-02-12 15:43

    The three ways I've got VS Code to use a JSON schema are ...

    So for something like the Azure Function schema from ... http://json.schemastore.org

    "json.schemas": [
      {
        "fileMatch": [
          "/function.json"
        ],
        "url": "http://json.schemastore.org/function"
      }
    ]
    
    1. In User Settings", i.e. as an element in the users settings.json in 'C:\Users\\AppData\Roaming\Code\User'

    2. In the "Workspace Settings", then in it's the "settings" section in the .code-workspace file ... assuming your're using a VS Code Workspace

    3. In the "Folder Settings", it's "settings" section in the settings.json, which is in the .vscode directory ... assuming your're using a VS Code Workspace

    The Folder takes precedence over Workspace, and Workspace over User

    And the Workspace and Folder work with relative paths, e.g. in the .code-workspace file ...

    "settings": {
      "json.schemas": [
        {
          "fileMatch": [
            "/task.json"
          ],
          "url": "./schema/tasks.schema.json"
        }
      ]
    }
    

    or in the Folder Settings settings.json in \.vscode\ ...

    "json.schemas": [
      {
        "fileMatch": [
          "/task.json"
        ],
        "url": "./schema/tasks.schema.json"
      }
    ]
    

提交回复
热议问题