Bug 481038 - Feature request: kate seems to be missing a non-strict JSON highlighting that shows less false positive errors
Summary: Feature request: kate seems to be missing a non-strict JSON highlighting that...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (other bugs)
Version First Reported In: 5.114.0
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-08 01:36 UTC by Ellie
Modified: 2025-07-16 06:59 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ellie 2024-02-08 01:36:49 UTC
SUMMARY

kate seems to be missing a non-strict JSON highlighting. It seems to be pretty common nowadays for various applications to support and use JSON with more lenient rules, the most common one I've seen allowing both `"` and `'` for strings, allowing `//` line and `/*` block comments, and allowing trailing comments in array lists and object maps. Some applications like VS Code give this a different name like "JSON with Comments" and sometimes use a different file ending like .jsonc but often they don't. I believe even VS Code uses files with this lenient JSON sometimes named .json for various things.

These files are currently a bit jarring to edit in kate because so much will be littered with bold red error markers. It would be nice if it were possible to turn that off. For example by providing "JSON (lenient)" and "JSON (strict)" variants in the "Markup" highlighting menu.

Personally, I think maybe the non-strict mode should even be the default, but I know you tend to be vary with changes of defaults. But I think having it cover more actual real world use cases without making too narrow assumptions, even if it leads to less useful error displays for some users unless manually changed to strict mode, makes slightly more sense.

STEPS TO REPRODUCE

1. Open a JSON file with comments
2. All the comments are marked red as errors
3. Try to find some way of fixing that

OBSERVED RESULT

There's only strict JSON highlighting, no lenient variant.

EXPECTED RESULT

There's a lenient JSON highlighting available, maybe even the default.


SOFTWARE/OS VERSIONS

Windows: 
macOS: 
Linux/KDE Plasma: openSUE Slowroll
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 5.114.0
Qt Version: 5.15.10

ADDITIONAL INFORMATION
Comment 1 Andrea Ippolito 2024-03-22 08:50:48 UTC
As far as I could see, at least as of version 24.02.0, the tool to "JSON Format Full File" is simply jq.

I'm checking if there's a way to let jq be more lenient, but if it exists, you can just pass whatever options to jq that achieves that result.

Or, you could change executable entirely, and use an external program you have installed which does the job.

Go to Settings, search for "External tools", then select "JSON Format Full File" and click on the Edit button below.
Comment 2 Ellie 2024-11-07 14:26:54 UTC
I think it makes sense to both have a  strict variant and a non-strict variant, since many users probably rely on both, as separate syntax options available at the same time. Given how many "JSON with comments" files are out there, my personal suggestion is that defaulting to the non-strict one would make more sense, but I understand many people disagree here. I hope this comment provides some insight on ideas for future plans.
Comment 3 Jonathan Poelen 2025-06-01 16:48:14 UTC
At present, json is not totally strict: trailing comma are not displayed in error, nor is the absence of comma between array and object (which makes it possible to support jsonline).

A non-strict variant already exists: javascript. It can be configured for json files in Settings -> Open/Save -> Modes & FileTypes. It does less checking of {}/[] matches, and there's no color distinction, but it should support all extensions.

We'll see about a non-strict variant and whether it should be the default.
Comment 4 Bug Janitor Service 2025-07-13 20:40:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/syntax-highlighting/-/merge_requests/719
Comment 5 Christoph Cullmann 2025-07-16 06:26:18 UTC
Git commit 99b75731857cc7c940e1c60c4a204740cdb9cdd9 by Christoph Cullmann, on behalf of Jonathan Poelen.
Committed on 16/07/2025 at 06:23.
Pushed by cullmann into branch 'master'.

add JSONC (JSON with Comments) highlighting

Although not recommended, the .json extension is used instead of .jsonc.
As a result, JSONC has a higher priority than JSON.

A  +35   -0    autotests/folding/test.jsonc.fold
A  +42   -0    autotests/html/test.jsonc.dark.html
A  +42   -0    autotests/html/test.jsonc.html
A  +35   -0    autotests/input/test.jsonc
A  +35   -0    autotests/reference/test.jsonc.ref
M  +3    -0    data/CMakeLists.txt
A  +50   -0    data/generators/generate-jsonc.pl
M  +10   -1    data/syntax/json.xml

https://invent.kde.org/frameworks/syntax-highlighting/-/commit/99b75731857cc7c940e1c60c4a204740cdb9cdd9
Comment 6 Christoph Cullmann 2025-07-16 06:26:20 UTC
Git commit 529a39f6cf8bb59b53749c6e4987e6ce52d860ed by Christoph Cullmann, on behalf of Jonathan Poelen.
Committed on 16/07/2025 at 06:23.
Pushed by cullmann into branch 'master'.

add JSON5 highlighting

A  +50   -0    autotests/folding/test.json5.fold
A  +57   -0    autotests/html/test.json5.dark.html
A  +57   -0    autotests/html/test.json5.html
A  +50   -0    autotests/input/test.json5
A  +50   -0    autotests/reference/test.json5.ref
A  +177  -0    data/syntax/json5.xml

https://invent.kde.org/frameworks/syntax-highlighting/-/commit/529a39f6cf8bb59b53749c6e4987e6ce52d860ed
Comment 7 Ellie 2025-07-16 06:59:40 UTC
I'm excited to see this addressed, thank you for your work! :-)