Quickly format JSON in Vanilla VIM
July 30, 2025 by John Rei Enriquez
You've experienced this for sure. Someone sends you a massive blob of JSON, and your first instinct is to Google “JSON formatter.”
Click the most appealing result, probably jsonformatter.org, paste it in, hit format, you either copy it back or just look trough it now that it's all formatted.
If you live inside Vim or Neovim like I do, context-switching to a browser just to format some JSON feels like you're doing extra work. Sure, you can do it—but wouldn’t it be better if you didn’t have to?
There are plugins in IDEs and it makes it easier, (I personally use conform.vim) but sometimes you are on a raw machine—no plugins, no cool IDE. Just you, a blinking cursor, and vim.
Luckily vim already has what you need. If Python’s installed (and it usually is), you can format JSON with a single command:
:%!python -m json.tool
That’s it. The %! part takes your whole buffer and pipes it through the json.tool module. Clean, readable JSON, right there in your editor.
If you want to make this even smoother, bind it to a key. I use <leader>jsonf.
In a LazyVim config that would look like
vim.keymap.set("n", "<leader>jsonf", ":%!python -m json.tool<CR>", { desc = "Format JSON in current buffer" })
Not life-changing—but definitely reduces friction in your workflow/dev flow.