21 May, 2015

Pretty printing JSON with Homebrew

You have an endpoint returning JSON. You could do
curl http://endpoint | pbcopy
and paste the text into TextMate, switch the filetype to JSON, and press Ctrl-Shift-H to have Textmate format the JSON. But that's way too many clicks.

'jsonpp' is an excellent command line utility for Terminal for pretty-printing JSON.
 brew install jsonpp
It's very useful combined with curl and pbcopy. It's the difference between a wall of JSON
curl http://endpoint
{"domain": {"domain": ".com", "endpoint": "http://e.esteelauder.na.us.dev.ncsa.elcdev.net/rpc/response.tmpl"}, "machine_name": "united-states", "name": "United States", "language": "en", "images": [{"group": "splash-background", "url": "/media/uploads/splash-background.jpg", "height": 976, "width": 768, "device": "iPad", "scale_factor": 1.0}, {"group": "sidenav-3mb-option1", "url": "/media/uploads/sidenav-3mb-option1.jpg",...
 and a much friendlier:
curl http://endpoint | jsonpp
 {
  "domain": {
    "domain": ".com",
    "endpoint": "http://e.xyz.foo.net/rpc/response.tmpl"
  },
  "machine_name": "united-states",
  "name": "United States",
  "language": "en",
  "images": [
    {
      "group": "splash-background",
      "url": "/media/uploads/splash-background.jpg",