Skip to content

Recognize .jsonc files without implying JSON5 support - #255

Open
leoshone wants to merge 1 commit into
NPP-JSONViewer:masterfrom
leoshone:feature/jsonc-narrow
Open

Recognize .jsonc files without implying JSON5 support#255
leoshone wants to merge 1 commit into
NPP-JSONViewer:masterfrom
leoshone:feature/jsonc-narrow

Conversation

@leoshone

@leoshone leoshone commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Following the review comment on #251 ("Let's remove JSON5 as 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 .jsonc extension, and a real .json5 file keeps behaving exactly as before this change.

Why anything at all

Notepad++ maps the .jsonc extension to the json5 language ("json5 jsonc" share one entry in the default langs.xml), so IsJsonFile() - 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:

if (languageType == LangType::L_JSON)
    return true;

if (languageType == LangType::L_JSON5)
{
    auto fileName = GetCurrentFileName();
    StringHelper::ToLower(fileName);
    return fileName.ends_with(L".jsonc");
}

return false;

A genuine .json5 document (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):

  • .jsonc and .json5 are both reported as the same language type (86 = L_JSON5), so the extension check is what actually separates them;
  • with draw-on-open enabled, the .jsonc document is drawn automatically while the byte-identical content named .json5 is not;
  • the rest of the jsonc assertions (snapshot caching, opt-in behaviour, manual refresh) pass unchanged.

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.
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.

1 participant