Pretty-print JSON on a Mac
Simple pretty-printing of JSON on a Mac
I’ve written npaste, a simple pastebin for text and images that supports encryption using GPG. My work involves a lot of JSON that I often need to share with others via Slack or other communication platforms. Sometimes the output is quite big and not very suitable for sharing inline. And in some cases the contents are sensitive and should not persist on the internet longer than necessary. In this post I’ll collect and present some useful commands that can be used to paste, format and share pretty-printed JSON data.
This post assumes you have the npaste-cli installed. Please see the readme for instructions on how to install it.
Let’s say you have the following unformatted JSON object in your clipboard:
{"id":1,"type":"object","name":"Clipboard test","value":"This is some random text"}
Now, all you have to do is type the following:
pbpaste | python -m json.tool | npaste --encrypt
You could of course create an alias or a function for this so that you don’t have to type in all this every time you want to paste something from your clipboard.
The npaste client will encrypt and upload your formatted JSON and return the URL in your terminal. You can then share it with friends and collegaues, knowing that it is stored encrypted on the server. Here’s a screenshot of how it looks on the npaste website:
If you’re reading this before 2021-06-29 you can also view the output directly on my npaste website: