Pretty-Print JSON in NeoVim/Vim using jq

August 23, 2019|
1 min read
  • vim

Originally posted by me on Hashrocket TIL

I've written here before about how to pretty-print JSON in Vim but since then I have found an even easier method using jq.

jq is an amazing command line utility for processing, querying and formatting JSON. I use it all the time when I get a response from an API request and I want to extract information or simply to pretty-print it with colors. All you have to do is pipe the curl results into jq:

curl https://til.hashrocket.com/api/developer_posts.json?username=doriankarter | jq

image

You can also use jq inside of NeoVim to pretty print a JSON string, right in your buffer using this command:

:%!jq

demo


© 2023, Dorian Karter