Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode json schema fileMatch pattern

In VSCode, I'm trying to add a sjson schema to a project I have. My .vscode/settings.json file is this:

{
    "json.schemas": [
        {
            "fileMatch": [
                "/*.json"
            ],
            "url": "https://path/to/url.json"
        }
    ]
}

```

This works, but it's currently applying to all .json files in all folders in the project, which I don't want. I want it to only apply to all .json files in the root directory. What do I have to put in the fileMatch property to enable this?

Update

Have tried the following. These work, but apply to every .json file:

  • "/*.json"
  • "*.json"

These don't work at all (no .json file gets the schema):

  • "${workspaceFolder}/*.json"
  • "${workspaceFolder}*.json"
  • "${workspaceFolder}\\*.json"
  • The above 3 without the {}
  • The above 4 with workspaceRoot
like image 339
Steve Avatar asked Jul 04 '26 03:07

Steve


1 Answers

I ran into something similar, but instead of wanting to add everything in the root, I wanted to add all JSON files that are in a subfolder of the workspace (root) folder. The solution I used was to add all JSON and then exclude the ones I didn't want (including the settings file itself):

{
    "json.schemas": [
        {
            "fileMatch": [
                "*.json",
                "!/.vscode/settings.json",
                "!/Some.json",
                "!/SomeOther.json"
            ],
            "url": "/Schema.json"
        }
    ]
}

The ones that needed to be excluded were just a few, so I could just name them all.

A similar approach mightwork in the original problem, with something like this:

{
    "fileMatch": [
        "*.json",
        "!/Folder1/*.json",
        "!/Folder2/*.json"
    ],
}

In only problem here is that VS Code doesn't seem to allow wild cards for folder names. So using Glob like matching to exclude /*/*.json or /**/*.json doesn't help, unfortunately.

like image 141
Gerbrand Stap Avatar answered Jul 06 '26 19:07

Gerbrand Stap