in Automation

XML and JSON prettify with Applescript and TextExpander

Generally, if you need to prettify JSON/XML/SQL code you can use your IDE builtin functions or you can count on many online services (for example):

For XML:
For SQL:

But each time you have to copy your code, paste in the broswer, click on a button, and then copy the result back to your editor. It’s not a drama, but there’s another way to do that: you can manage and automate XML and JSON prettify with Applescript and TextExpander by creating a snippet to get data from the system clipboard and apply a transformation to prettify your code.

And cos you can do that using only pure Javascript, you can do the trick on both OsX and iOS devices.

To prettify code I used the great work made by Vadim Kiryukhin which can be found here.

I modified the scripts to work with TextExpander and create a group called “Prettify” with the following snippets:

,,jpp: JSON prettify;
,,xpp: XML prettify;
,,spp: SQL prettify.

So, when you need, just select and copy your code and type the appropriate abbreviation and the result will be expanded in place.

It’s super-easy and remember, it works on iOS too!

You can download the action group here and look at the code inside.