Curl, JSON and Pretty Print

Curl is a wonderful thing. The output can be a bit messy, however.

This python pipe pretty prints your otherwise messy JSON output.

1
$ curl -H 'Accept: application/json' http://localhost:3001/myserver/cmd | python -mjson.tool

Or, using Ruby, if necessary run

1
sudo gem install json

then pipe your output.

1
cat myfile.json | prettify_json.rb

An even nicer solution is this node script, written specifically to handle curl output. You’ll need to make sure you’ve installed Node.js before you can use it.

Comments