13

Given a file with a large JSON object all on one line like

{"versions":[{"count":2,"version":""},{"count":1,"version":"1.1.1"},{"count":14,"version":"2.9"},{...

How can I format this to be human readable in Vim?

16

Or you can install jq which is faster (written in C) from your package manager or from source and then in vim, type :

:%!jq .
12

This one-liner works well to format JSON in Vim into a human readable form:

:%!python -m json.tool

1

If PHP is available, add the tool jf as a JSON Formatter by Composer:

$ composer global require codegear/json-formatter

Then Format current file:

:%!jf %

Or add a keymap in vimrc:

nnoremap <Leader>jf :%!jf %<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.