Skip to content

[json] schema fileMatch for all *.json files in root folder #44135

Closed

Description

@stkb
  • VSCode Version: 1.20.1
  • OS Version: Win 10
    Does this issue occur when all extensions are disabled?: Yes

I've tried asking this on stackoverflow and gitter without success. I have a project with (among other things) lots of .json files. This is the .vscode/settings.json file:

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

The problem is that this matches all .json files in the project, but I need it to match only *.json files in the root directory. What can I put in fileMatch to enable this, or can this not be done with the file matching?

Activity

  1. added
    json
    on Feb 21, 2018
  2. RMacfarlane commented on Feb 21, 2018

    @RMacfarlane

    Does "./*.json" work?

  3. stkb commented on Feb 21, 2018

    @stkb
    ContributorAuthor

    Unfortunately not, and btw I had it slightly wrong in my first post (now edited)

    • "*.json" matches all .json file in all directories.
    • "/*.json" matches only .json files 1+ levels down
    • "./*.json" doesn't seem to match any files.
  4. added
    bug
    on Mar 1, 2018
  5. aeschli commented on Jun 25, 2018

    @aeschli
    Contributor

    The patterns currently just match against the end of the full file path. The matcher is not aware of the workspace folder.
    A workaround for you is to add the name of the root folder to the pattern, e.g. myroot/*.json, but of course, that's not ideal.

    We would need something like a `${workspaceFolder} variable to do this properly.

  6. 4 remaining items

  7. added
    help wanted
    on Feb 26, 2024
  8. soreavis commented on Jul 17, 2026

    @soreavis
    Contributor

    Martin Aeschlimann (@aeschli) I'd like to take this. The matcher lives in vscode-json-languageservice, but there's a second piece: the single-folder .vscode/settings.json case passes folderUri as undefined to the service (jsonClient.ts), so the client has to hand the folder over for anything workspace-relative to work there.

    On syntax — you mentioned ${workspaceFolder}, and mgzenitech suggested a leading / anchoring to the folder root like .gitignore. I prototyped the leading-/ version: a contained change in FilePatternAssociation, fully backward compatible (bare *.json unchanged; only a leading-/-with-folderUri pattern, which is a no-op today, changes), with 5 new unit tests and the full suite green — plus 40+ edge cases I ran against the matcher (special-character folder names, encoded and unicode paths, remote schemes, exclusions). Either way the folder should be matched by prefix rather than expanded into the glob — the glob has no escape, so a folder named my[proj] would break an injected pattern.

    Which would you rather, leading / or ${workspaceFolder}? Once you pick I'll open both PRs (service + client).

  9. aeschli commented on Jul 20, 2026

    @aeschli
    Contributor

    ${workspaceFolder} would be my favorite. It would be expanded on the client. The server shouldn't need to know about workspace folders. So the server API stays unchanged

  10. soreavis commented on Jul 20, 2026

    @soreavis
    Contributor

    Martin Aeschlimann (@aeschli) done — #326706.

    • Expanded on the client when the json.schemas settings are collected; the server stays untouched, so it's one PR instead of the two I offered.
    • Expansion happens only where the folder is unambiguous: folder settings in a multi-root workspace, and workspace settings of a single-folder workspace.

    One caveat for review: the folder is matched textually inside the pattern and the service's glob has no escape, so folder names containing [, { or ? won't match — details in the PR.

  11. added a commit that references this issue on Sep 26, 2026
    fe573b2
  12. added
    unreleased
    on Sep 30, 2026
  13. added
    insiders-released
    verification-needed
    and removed
    unreleased
    on Sep 30, 2026
  14. added
    verified
    and removed
    verified
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requesthelp wantedinsiders-releasedjsonverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions