JSON pretty formatting in vim

Dawid Laszuk published on
1 min, 115 words

Quick ad hoc command:

:%!python -m json.tool
For reusing and typing more update your `.vimrc` file with:
com! FormatJSON %!python -m json.tool
After this you should be able to use :FormatJSON command.

This would convert:

[{"classification":"emrfs-site", "properties":{"fs.s3.consistent.retryPeriodSeconds":"10", "fs.s3.consistent":"true", "fs.s3.consistent.retryCount":"5", "fs.s3.consistent.metadata.tableName":"EmrFSMetadata"}, "configurations":[]},{"classification":"spark", "properties":{"maximizeResourceAllocation":"true"}, "configurations":[]},{"classification":"spark-env", "properties":{}, "configurations":[{"classification":"export", "properties":{"PYSPARK_PYTHON":"/usr/bin/python3"}, "configurations":[]}]}]

into

[
    {
        "classification": "emrfs-site",
        "configurations": [],
        "properties": {
            "fs.s3.consistent": "true",
            "fs.s3.consistent.metadata.tableName": "EmrFSMetadata",
            "fs.s3.consistent.retryCount": "5",
            "fs.s3.consistent.retryPeriodSeconds": "10"
        }
    },
    {
        "classification": "spark",
        "configurations": [],
        "properties": {
            "maximizeResourceAllocation": "true"
        }
    },
    {
        "classification": "spark-env",
        "configurations": [
            {
                "classification": "export",
                "configurations": [],
                "properties": {
                    "PYSPARK_PYTHON": "/usr/bin/python3"
                }
            }
        ],
        "properties": {}
    }
]