Registered Member
|
Hello, I'd like to know if there's a way to reformat a json so it's human readable. I found a link posted on 2013 that speaks of a set of plugins (they told that have been integrated to kate), that allow with some other things "Pretty JSON: Pretty format of a JSON code selected".
Is that hidden somewhere? I'm on kate 16.12.3 |
Mentor
|
|
Registered Member
|
Another alternative I thought of was to use the external tool, but it seem that it was removed from kate even before that the tools ( https://kate-editor.org/2011/08/09/main ... ls-plugin/ ), so it's neither a solution.
Any other ideas? |
Registered Member
|
I have the same problem, so I am using this post instead of creating a new one.
Is it possible that there is no way whatsoever to let kate indent a json??? I think it's a so important feature that it cannot be true, so maybe there is some way I was not able to find. Otherwise, is there any other lightweight text editor of KDE that I could use that have this functionality? Thanks |
Registered Member
|
I figured out to write my own kate script to do it.
The following is the relevant bits from that script (for Kate 4, I believe some parts probably need to be changed for Kate 5; not sure what though). Save it under the katepart config directory under script/commands as somename.js. Of note, it uses tabs for indentation and formats objects of simple k:v pairs on a single line. The comment with test json is intended for testing the formatting so you can see how it formats different things. Feel free to modify/redistribute/whatever as you please.
airdrik, proud to be a member of KDE forums since 2008-Dec.
|
Registered Member
|
That looks nice! I don't know how to set up a kate script, but I can find out. Why don't you publish it on github with a md documentation? |
Registered Member
|
Perhaps I'll get around to it. It has worked so far for what I've used it for, but would probably want to put more care into it when publishing for a general audience. (or if you want to do that, by all means go right ahead)
Some resources: Blog post introducing Kate's scripting capabilities: https://kate-editor.org/2009/10/29/exte ... h-scripts/ Full documentation: https://docs.kde.org/stable5/en/applica ... pting.html There are a couple of scripting plugins on opendesktop.org, though the pickings are thin. One in particular that stood out: https://www.opendesktop.org/p/1126932/ - a large collection of scripted commands. The github repo is well-structured and includes a script for converting from kate 4 to 5.
airdrik, proud to be a member of KDE forums since 2008-Dec.
|
Registered Member
|
Thanks so much for this. I updated the script to work with katepart5 / KDE Plasma 5
|
Registered Member
|
Very useful script, thank you for the idea! Formatting can be done more easily. Didn't notice any problems with my version:
The result for the test jSON:
|
Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]