Skip to content

fix: JSON parsing with trailing commas enabled#37

Merged
yCodeTech merged 2 commits into
masterfrom
fix/issue-36/json-parser-errors-on-trailing-commas-in-lang-config
Jul 20, 2026
Merged

fix: JSON parsing with trailing commas enabled#37
yCodeTech merged 2 commits into
masterfrom
fix/issue-36/json-parser-errors-on-trailing-commas-in-lang-config

Conversation

@yCodeTech

@yCodeTech yCodeTech commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Fixes #36.

The issue

This extension uses jsonc-parser to make sure the syntax of the JSON is correct and not malformed. During parsing of JSON files, the parser will throw a ValueExpected error when it reaches a comma and unexpectedly encounters a closing bracket straight after. Trailing commas are disabled in the parser by default as it's not standard in JSON or JSONC. So it expects some kind of value after all commas.

The fix

Luckily, the parser has an option to enable trailing commas. So the fix is to just pass the allowTrailingComma: true option to the parser in the readJsonFile util function. This will then skip over and prevent the ValueExpected error for trailing commas.


Copilot Summary

This pull request improves the robustness and clarity of JSON file parsing in the src/utils.ts utility functions. The key changes enhance error handling and allow for more flexible JSON syntax.

JSON parsing improvements:

  • The readJsonFile function now allows trailing commas in JSON files by setting the allowTrailingComma: true option in the jsonc.parse call. This makes the parser more permissive and user-friendly.

Error reporting enhancements:

  • The constructJsonParseErrorMsg function now includes both the raw error code (in brackets) and a more readable, space-separated error name in its output. This provides clearer and more informative error messages for debugging JSON parsing issues.

Fixes #36.

During parsing of JSON files, the parser will throw an `ValueExpected` error when it reaches a comma and unexpectedly encounters a closing bracket straight after. Trailing commas are disabled in the parser by default as it's not standard in JSON or JSONC. So it expects some kind of value after all commas. Luckily, we can enable trailing commas...

- Fixed `ValueExpected` JSON parse error for trailing commas by enabling the `allowTrailingComma` parse option in `readJsonFile` util function. This is especially useful when parsing language config files, when the contributing extension has auto-formatting enabled for trailing commas.
Copilot AI review requested due to automatic review settings July 20, 2026 05:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the JSON-reading utility to successfully parse JSON/JSONC files that include trailing commas, addressing the ValueExpected parse error described in issue #36 (notably seen in VS Code extension language configuration files).

Changes:

  • Enable allowTrailingComma in the jsonc-parser options used by readJsonFile.
  • Add an inline comment clarifying the parser options and intent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Refactored the JSON parse error messages in `constructJsonParseErrorMsg` util function to include the original error name, as well as the formatted name, just to ensure the errors have a proper error code for debugging.
@yCodeTech
yCodeTech merged commit 83ef690 into master Jul 20, 2026
1 check passed
@yCodeTech
yCodeTech deleted the fix/issue-36/json-parser-errors-on-trailing-commas-in-lang-config branch July 20, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Error thrown when parsing JSON config file for C# extension with trailing commas

2 participants