How to Format JSON in Vim

Tyler Tyler (291)
5 minutes

Vim is amazing. Well, Python is doing all the work, but I still like Vim. Learn how to format JSON in Vim like a pro with this short guide!

tl;dr

Paste your json, and run this in vim normal mode.

:%!python -m json.tool
Posted in these interests:
h/vim23 guides
h/python67 guides
Paste your ugly JSON in Vim

Enter visual mode using 'v' and paste the ugly JSON.

Use Python to format the JSON

In normal mode type:

:%!python -m json.tool

Beautiful.

Dayne Dayne (57)
0

You probably already know how to use vim's basic undo and redo features. For a quick refresher, read this short tutorial on how to use vim redo and undo.