fix: JSON parsing with trailing commas enabled#37
Merged
yCodeTech merged 2 commits intoJul 20, 2026
Merged
Conversation
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.
There was a problem hiding this comment.
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
allowTrailingCommain thejsonc-parseroptions used byreadJsonFile. - 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
deleted the
fix/issue-36/json-parser-errors-on-trailing-commas-in-lang-config
branch
July 20, 2026 06:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ValueExpectederror 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: trueoption to the parser in thereadJsonFileutil function. This will then skip over and prevent theValueExpectederror for trailing commas.Copilot Summary
This pull request improves the robustness and clarity of JSON file parsing in the
src/utils.tsutility functions. The key changes enhance error handling and allow for more flexible JSON syntax.JSON parsing improvements:
readJsonFilefunction now allows trailing commas in JSON files by setting theallowTrailingComma: trueoption in thejsonc.parsecall. This makes the parser more permissive and user-friendly.Error reporting enhancements:
constructJsonParseErrorMsgfunction 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.