Bug 505530

Summary: Saving JSON file deletes lines
Product: [Applications] kate Reporter: Nighteyes <mk_spamguard>
Component: applicationAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED UPSTREAM    
Severity: major CC: waqar.17a
Priority: NOR    
Version First Reported In: 25.04.2   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: The json file in question.

Description Nighteyes 2025-06-12 15:51:32 UTC
Created attachment 182230 [details]
The json file in question.

SUMMARY
When saving this specific json file a reformat is triggered (while I have this disabled in my settings) and a whole entry is removed. With this bug I can't rely on Kate for any json work.
I tried restarting the editor, thinking it might be a random bug. I also tried moving the file (outside the git repo) on disk and I keep getting the same result. 

STEPS TO REPRODUCE
1. Open the json file.
2. Hit "control + s" or click the save button.
3. Watch the text disappear.

OBSERVED RESULT
Text just disappears, I'm glad I had the file in git.

EXPECTED RESULT
No reformatting and lines deleted with a json file on disk.

SOFTWARE/OS VERSIONS
Operating System: EndeavourOS
KDE Plasma Version: 6.3.5
KDE Frameworks Version: 6.14.0
Qt Version: 6.9.1
Kernel Version: 6.14.10-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 32 × AMD Ryzen 9 7950X3D 16-Core Processor
Memory: 62.4 GiB of RAM
Graphics Processor: AMD Radeon RX 7900 XTX
Comment 1 Waqar Ahmed 2025-06-13 06:13:36 UTC
Unable to reproduce.

> while I have this disabled in my settings

Where in the settings?

Which plugins do you have enabled?

Are you using "Formatting" plugin?
Comment 2 Nighteyes 2025-06-13 11:28:46 UTC
I only have the default plugins active including the LSP Client which has a setting Format on typing and Format on save among others.

The full list of plugins I have active is:
Document Switcher
Document Tree
External Tools
Formatting
LSP Client
Project Plugin
Search & Replace
Terminal
Text Filter

To be honest I did not really know about the plugins yet. I disabled them all, and enabled one by one. The culprit is indeed the formatting plugin. Disabling the formatting plugin removes the weird behaviour that lines get deleted.
Comment 3 Waqar Ahmed 2025-06-13 11:46:56 UTC
In the formatting plugin settings, do you have the following line?

"formatterForJson": "jq",

or is it something else? If its set to "jq" then can you run the following command and check if the json lines get deleted?

cat JSON_FILE.json |  jq . --indent 4 -M
Comment 4 Nighteyes 2025-06-13 12:34:44 UTC
That indeed produces the same output. It might be related to the fact that there is a duplicate entry in the json file at the same level? That might not be the nicest form of json, but I would not expect it to be automatically deleted without warning.
Comment 5 Waqar Ahmed 2025-06-13 12:50:14 UTC
I'd suggest you take this issue up with the "jq" team. Kate just invokes "jq" to do the formatting.
On my end with the following jq version I dont see any deleted lines:

jq --version
jq-1.7.1

JQ lives here: https://github.com/jqlang/jq

---

You can use "prettier" or "clang-format" for formatting json. Search for "Formatting" in the KDE help center to learn more about the plugin. A simple example of how you can modify the settings, put the following in "User Settings" tab:

{
    "formatOnSave": true,
    "formatterForJson": "prettier",
    "jq": {
	"formatOnSave": false
    }
}

first line enables formatOnSave. second line changes the json formatter to prettier. third line disables "formatOnSave" just for jq
Comment 6 Nighteyes 2025-06-13 13:29:50 UTC
Thanks for the info, i'll do that. The version of jq I'm running is 1.8.0.