DEV Community

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

Posted on

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 ✌️

Top comments (0)