Skip to content

[json] support setting schema associations at runtime #96120

Closed

Description

@ayqy

Related PR: #73424
Related FR: #69868

Feature Request: Configure jsonValidation contribution point dynamically.
Use Case: Twin json files like myFile.json and myFile.js, which file name is the same as another file under the same directory, but file extension name is normal .json. So, glob matching or content detection does not work well, dynamic configuration is required.

Activity

  1. aeschli commented on Apr 27, 2020

    @aeschli
    Contributor

    How would the dynamic configurator know what schemes applies to which file?

  2. ayqy commented on Apr 27, 2020

    @ayqy
    Author

    In my case, there are some twin files like this:

    .
    ├── project.json
    └── src
        ├── foo.js
        ├── foo.json
        ├── bar.js
        ├── bar.json
        └── non-match.js
    
    

    I wanna to configure a specified JSON Schema to validate foo.js and bar.js under my project (detected from project.json at project root folder).

    As you see, static glob is not working. Any workarounds or a more graceful solution will be great as well.

  3. aeschli commented on Apr 27, 2020

    @aeschli
    Contributor

    One possible solution is to specify the schema in the JSON file
    "$schema": "..."

  4. ayqy commented on Apr 27, 2020

    @ayqy
    Author

    Not really bad, but it's a little bit dirty for someone who reads and parses JSON key-values from the original file. And all consumers (such as our source code analysis service, native application...) have to take care of $schema from now on.

    But anyway I think it's accepted for this case, so you can close this or take it into consideration for other clean approaches in the future. Thanks a lot.

  5. changed the title [-]Configure JSON Schema dynamically[/-] [+][json] support setting schema associations at runtime[/+] on May 6, 2020
  6. added
    feature-request
    json
    on May 6, 2020
  7. dsherret commented on Aug 29, 2021

    @dsherret

    I have a use case for this. In my scenario, the schema of the JSON file changes based on the plugins specified, for example:

    {
      "incremental": true,
      "lineWidth": 160,
      "json": {
        "indentWidth": 2,
      },
      "typescript": {
        "useTabs": true
      },
      "includes": [
        "**/*.{ts,tsx,js,jsx,json}"
      ],
      "plugins": [
        "https://plugins.dprint.dev/typescript-0.48.0.wasm",
        "https://plugins.dprint.dev/json-0.12.1.wasm"
      ]
    }

    Given the plugins specified, the schema of the plugin specific properties change (ex. in this case the "typescript" and "json" properties are added to the schema). I previously thought #98443 would solve my use case, but it has the problem of the "plugins" needing to be kept in sync with the "$schema" and it's annoying for the user to have to specify this.

    Instead, it would be neat if the dprint vscode extension could programatically generate a schema based on the plugins in the plugins array and use that to help set the schema of the file (so this would be ideally programatically specified rather than a uri, but as a workaround I could create a web server route with some query parameters to make this work).

  8. aeschli commented on Aug 31, 2021

    @aeschli
    Contributor

    David Sherret (@dsherret) What you want can be done with a programmatic schema. See #127812

  9. dsherret commented on Aug 31, 2021

    @dsherret

    Martin Aeschlimann (@aeschli) oh great! That looks like it will work. Thanks so much!

  10. added
    unreleased
    on Jul 24, 2026
  11. added
    insiders-released
    verification-needed
    and removed
    unreleased
    on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestinsiders-releasedjsonverification-needed

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions