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
You can also use jq
inside of NeoVim to pretty print a JSON string, right in your buffer using this command:
:%!jq