Recognize .jsonc files without implying JSON5 support - #255
Open
leoshone wants to merge 1 commit into
Open
Conversation
IsJsonFile() used to accept every L_JSON5 document. Notepad++ maps the
.jsonc extension to the json5 language ("json5 jsonc" share one entry in
the default langs.xml), but that also pulled in genuine .json5 documents,
whose syntax (unquoted keys, single-quoted strings) the parser does not
support: they used to be silently ignored by the plugin and would now be
parsed and reported as an error.
Accept the json5 language for .jsonc files only, so a real .json5 file
keeps behaving exactly as before this change.
Verified end to end: .jsonc and .json5 are both reported as the same
language (86) by Notepad++, the .jsonc document is drawn while the .json5
one is not, and the existing jsonc assertions still pass.
leoshone
added a commit
to leoshone/JSON-Viewer
that referenced
this pull request
Sep 7, 2026
…NPP-JSONViewer#255 opened - NPP-JSONViewer#251 was approved and merged - the small-pure-PR strategy works. - Upstream moved to fa8d2b9 (settings saved on exit via writeIfChanged, include reordering) and renamed our TREE_ZOOM key to TREE_ZOOM_LEVEL; documented the consequences for the next integration sync. - NPP-JSONViewer#253/NPP-JSONViewer#254 rebased onto fa8d2b9, all three PRs mergeable again. - NPP-JSONViewer#255 opened for the narrow jsonc recognition, with the forward pointer added to the NPP-JSONViewer#251 thread as planned.
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.
Following the review comment on #251 ("Let's remove
JSON5as it is not supported currently by the plugin") - this is a version that does not accept the JSON5 language at all. It only recognises the.jsoncextension, and a real.json5file keeps behaving exactly as before this change.Why anything at all
Notepad++ maps the
.jsoncextension to the json5 language ("json5 jsonc"share one entry in the default langs.xml), soIsJsonFile()- the gate for draw-on-open, follow-tab and auto-format - returned false for every jsonc document, even though the parser itself handles jsonc content fine (ignoring comments and trailing commas is configurable and on by default).The change
IsJsonFile()now accepts the json5 language only when the current file's extension is.jsonc:A genuine
.json5document (unquoted keys, single-quoted strings) does not match the extension check and keeps being ignored by the plugin exactly as it was before - no parsing, no error dialog, no change in behaviour.Verification
Measured end to end in a real Notepad++ (8.9.6.2, default langs.xml):
.jsoncand.json5are both reported as the same language type (86 =L_JSON5), so the extension check is what actually separates them;.jsoncdocument is drawn automatically while the byte-identical content named.json5is not;