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.
Written by Colin Dean
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#