n9qokq
Last Updated: November 15, 2018
·
65
· colindean

Use jq to format JSON in Vim

I just added a little snippet to my .vimrc that allows me to format JSON in two keystrokes:

com! FormatJSON %!jq .
nmap =j :FormatJSON<CR>

You need to have jq installed. There are other tips out there that use Python but have various caveats. I've always got jq available when I've got my .vimrc so this is preferable – and faster performance, in a few real world tests – for me.

Filed Under