Some years ago, I wrote a post on Formatting XML in Kate - KDE Editor. This one below is for JSON format. Like the XML one this one also makes use of a tool installed on your machine and is invoked from Kate as a filter.
Kate is one awesome editor ( If you don't like Vim for its 'CLI'ness )
When working from the command line we can use a handy tool 'jq' to format JSON files and pretty print them. Well, the good news is we can use the same from within Kate as well
But it is a tedious task to use it when you have some content in Kate ( more so if it is an unsaved file ) and want to format it.
Incase, you don't have jq installed, simply hit
sudo apt-get install jq
and that will install it for you.
If you use jq you would do something like this,
Tested with ,
KDE Development Platform: 5.68.0
Kate is one awesome editor ( If you don't like Vim for its 'CLI'ness )
When working from the command line we can use a handy tool 'jq' to format JSON files and pretty print them. Well, the good news is we can use the same from within Kate as well
But it is a tedious task to use it when you have some content in Kate ( more so if it is an unsaved file ) and want to format it.
Incase, you don't have jq installed, simply hit
sudo apt-get install jq
and that will install it for you.
If you use jq you would do something like this,
- Save File ( MySavedFile.xml )
- Go to Command Line
- cat MySavedFile.txt | jq '.' - > MySavedFile.txt
and then reload our file in Kate.
- Select text ( Complete or Partial )
- Hit 'Ctrl + \' or go to Tools -> Filter Text
- Incase your Kate does not have the option for 'Filter Text' under tools, you just need to enable the 'Text Filter' plugin.
- Go to Settings -> Plugin -> Enable 'Text Filter' and you are done.
- Type 'jq '.' -' and VoilĂ ! we have a formatted JSON
- Incase, you don't wish to modify the existing text, make sure you select 'Copy the result instead of pasting it'
- Another good thing is that Kate caches the jq command in the text filter so you don't have to type it in again and again.
Kate: 19.12.3
Qt: 5.12.8KDE Development Platform: 5.68.0
on Ubuntu 20.04.3 LTS
Comments
Post a Comment