sftools - bakkeby/dusk GitHub Wiki
I wanted to present two simple format tools which main purpose is to "beautify" minified structured data, as in making it readable.
One is for JSON data and the other is for XML.
What is the point of these tools when there are other comprehensive tools around that does the same job? For example you can pass flattened json through jq
and it will beautify it just fine.
The answer is that all such tools do an excellent job at parsing structured data - to such a degree that they also apply validation of the data. Consequently if the data is not valid then the tool may also refuse to format it, complaining about formatting errors instead.
For work purposes I need to do a lot of analysis involving flattened JSON and XML data. My primary concern is to be able to read the data, and quickly. I don't want to waste time with tools that refuse to do the job because of a missing bracket or otherwise incomplete data.
The simple format tools applies formatting on a best effort basis following basic rules.
One example would be to add a newline and indentation following a square bracket, while taking into account escaped characters and whether the text is within a double or single quoted string.
The tools can be found here:
The tools can be used from the command line or whatever best suits your needs.
I have this integrated in Sublime Text such that I can just select some text and trigger the Ctrl+Shift+o
keybinding to beautify it.
This is achieved through a Sublime Text package called FilterPipes which allows for the selected text to be passed to an arbitrary command, and the selected text will be replaced with the output of said command.
To avoid having to set up different keybindings depending on the format of the data I have a single keybinding set up to trigger a script like this:
{
"keys": ["ctrl+shift+o"],
"command": "filter_pipes_process",
"args": {
"command": ["beautify.sh"],
"shell": false
}
},
That script tries to identify the type of data and to select the formatting tool accordingly (choosing between sfjson
, sfxml
, sqlparse
and prettier
).
Having beautify formatters like this straight in the text editor has saved me a lot of time.
Refer to:
- https://packagecontrol.io/packages/FilterPipes
- https://prettier.io/
- https://pypi.org/project/sqlparse/
- beautify.sh
Back to Other scripts and life hacks.