Format JSON in Vim

Jul 23, 2018  

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!