Format JSON in Vim

linux vim

Update: A much more versatile tool for formatting JSON is jq, which doesn't require Python to be installed

Just a quick tip if you're wanting to format JSON. Obviously it requires Python to be installed.

$ cat test.json | python -m json.tool

Additionally, if you use vim, it's worth pointing out that it's easy to use here too:

:%!python -m json.tool

And that's it!

Published on 23 Jul 2018