Small Helpers: Indent XML (and JSON) in Sublime Text

Tools do not have to be big to be a great help. One of those little helpers I use often when working with XML and JSON is Indent XML. It is a plugin for Sublime Text (a sophisticated text editor) and helps you to turn this

<root><node attr="1" ><node attr2="4"/></node><node>hello</node></root>

into this

1
2
3
4
5
6
<root>
    <node attr="1">
        <node attr2="4"/>
    </node>
    <node>hello</node>
</root>

If you work with JSON, you can do the same and turn this

{ "root": [ { "field": "val1", "field2": "val2" }, { "arr": [1, 3, "three"] }] }

into this more readable structure:

{
    "root": [
        {
            "field": "val1",
            "field2": "val2"
        },
        {
            "arr": [
                1,
                3,
                "three"
            ]
        }
    ]
}

You can install this plugin using Package Control for Sublime Text 2 and 3. Select the block of JSON or XML you want to indent and call it over the selection menu:

Selection -> Format -> Indent XML

That is all you need to do and you no longer have to work with long lines of JSON or XML. Try it!