DEV Community

Cover image for PrettyPrint JSON in OSX cli
prasanna malla
prasanna malla

Posted on

2

PrettyPrint JSON in OSX cli

When testing APIs its easy to use curl in your terminal but the output is definitely not pretty. We can pipe the command to python -m json.tool and have it readable but we want it to be pretty)

We will be using homebrew as the package manager to install pygments and python and use this as the default version with pyenv. First we will uninstall any previous version of python installed eg: pyenv uninstall 3.10.5 && pyenv rehash

Let’s start brewing)



brew install @python3.11
cd ~/.pyenv/versions
ln -sfv "$(brew --prefix python@3.11)" 3.11
cd "$(brew --prefix python@3.11)" 
ln -sfv Frameworks/Python.framework/Versions/3.11/include/python3.11 include
cd "$(brew --prefix python@3.11)/bin" 
ln -sfv idle3 idle
ln -sfv pip3 pip 
ln -sfv python3 python
ln -sfv wheel3 wheel
pyenv rehash
pyenv global 3.11
python --version
brew install pygments


Enter fullscreen mode Exit fullscreen mode

Now we can pipe our API call to json.tool for formatting and pygments for JS like colorized output
curl -X GET β€˜https://api.printful.com/store/products/307743308' | python -m json.tool | pygmentize -l javascript

Terminal pretty-prints API response<br>

 
Finally, I can get back to writing my next Vendure plugin for Printful! Follow me on twitter @prasmalla for updates on the plugin ✌️

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry πŸ•’

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series πŸ“Ί

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series πŸ‘€

Watch the Youtube series

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay