Formatting JSON with VIM

Written by

in

I am working on an analytics project where we generate very complicated medical analysis and put it in a hierarchical data model.

json

{ "test" : { "test1" : "val1" } }

Open the JSON in vim and use python -m json.tool

:%!python -m json.tool

Results

json

{
    "test": {
        "test1": "val1"
    }
}

Note: jq (jq is another option, but… not always available on every system, python tends to work everywhere).

References