Last Updated: February 25, 2016
·
855
· tacahiroy

Vim: 'errorformat' setting for JSON syntax checker

I was inspired by Rodrigo's tip and noticed this Python module provides enough information for validating a JSON file.
I often edit JSON file as a Chef data bag, therefore I configured Vim like this:

" JSON (Chef)
autocmd BufRead,BufNewFile knife-edit-*.js,*.json setlocal filetype=javascript.json
autocmd FileType *json* setlocal makeprg=python\ -mjson.tool\ 2>&1\ %\ >\ /dev/null
                     \| setlocal errorformat=%m:\ line\ %l\ column\ %c\ %.%#

You can check a JSON syntax like this:

:make

Gist is also available: https://gist.github.com/4459707