Skip to content

Support comments in JSON configuration (aka JSONC) #496

@Avasam

Description

@Avasam

Problem

If my JSON in contains_json contains comments, the parser will fail.
Example:

[".vscode/extensions.json".contains_json]
"unwantedRecommendations" = """
  [
    // VSCode has implemented an optimized version
    "coenraads.bracket-pair-colorizer",
    "coenraads.bracket-pair-colorizer-2",
    // Lots of conflicts
    "esbenp.prettier-vscode",
    // Replaced by ESLint
    "eg2.tslint",
    "ms-vscode.vscode-typescript-tslint-plugin",
    // Obsoleted by Pylance
    "ms-pyright.pyright",
    // Not configurable per workspace, tends to conflict with other linters
    // Use eslint-plugin-sonarjs for JS/TS projects
    "sonarsource.sonarlint-vscode"
  ]
"""
"[python]" = """
  {
    "editor.tabSize": 4,
    "editor.rulers": [
      72, // PEP8-17 docstrings
      // 79, // PEP8-17 default max
      // 88, // Black default
      99, // PEP8-17 acceptable max
      120 // Our hard rule
    ]
  }
"""

Results in

".vscode/extensions.json".contains_json.unwantedRecommendations.value: Invalid JSON (json.decoder.JSONDecodeError: Expecting value: line 2 column 5 (char 8))
".vscode/settings.json".contains_json.[python].value: Invalid JSON (json.decoder.JSONDecodeError: Expecting value: line 4 column 11 (char 62))

Possible solution

Support parsing JSON with Comments (aka JSONC)
Note that this is different than #406 . I am not asking for the comments to be kept when using nitpick fix, I just want the parser to at least ignore comments and not fail.

For more information, see the CONTRIBUTING guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Upvoted / Requests

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions