GitHub

jfmt is a simple plugin for vim to automatically validate and format/pretty-print JSON files.

vim-jfmt

Installing

Ensure you have jq installed and available in your local $PATH

Then, add to your .vimrc using your plugin manager of choice; e.g. vundle:

Plugin 'bcicen/vim-jfmt'

Usage

By default, jfmt will only validate JSON files on save, opening a location list with any parse errors encountered.

To manually format/pretty-print the open file, use the :Jfmt command. To automatically run this on save as well, simply add the below to your .vimrc:

let g:jfmt_autofmt  = 1

Options

Additional options may be provided to jq by setting g:jfmt_jq_options:

" use tabs instead of spaces for indentation
let g:jfmt_jq_options = '--tab'

Likewise, the default filter(.) can be changed by setting g:jfmt_jq_filter

Read the original on github.com ↗