David Jones

Formatting xml and json

I have recently been working with large sample of XML. After pasting it into Sublime I was left with a large chunk of unformatted mess.

I then came across this plugin for Sublime that formats it for you. It also works with JSON.

To install this just download the two files and save them into the User directory of the Package directory. To get there easily while in Sublime go to Preferences -> Browse Packages... . Next we need to set the short cuts. While in Sublime go to Preferences -> Key Bindings - User and add this code.

[
  { "keys": ["super+shift+x"], "command": "tidy_xml" },
  { "keys": ["super+shift+j"], "command": "prettify_json" }
]

Now you can use the short cut command + shift+ x to format your XML. One thing to not is that it doesnt seem to work if there is white space before the XML begins.

If nothing happens you can open Sublimes console using the short cut ctrl + ` to get more information.