Format JSON in 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
:
allows a command to be entered%
selects all lines (alternatively you can select a line number or range)!
allows a shell command to be executed
And that’s it!