All posts

How to pretty print JSON in ruby

The easiest way I’ve found to accomplish this is using puts

The call below will print the json object and return nil

puts data.to_json
{"admin":true,"email":"admin@gmail.com"}

If you need the object to be printed on a multi-line basis you can use the command line tool jsonpp.

After installing you can copy an object like the one above and paste it into its own file and then run the command:

jsonpp path/to/file.json

Which will produce the following output:

{
  "admin": true,
  "email": "admin@gmail.com"
}%

Further reading:

Postscript:

I built two products to help fund continued efforts for this website, it would mean a lot if you would check them out:
1. 2500+ Words for the Undermotivated Software Engineer - A short essay I wrote on the titled topic ($3).
2. Build 3 Chrome Extensions in Under 2 Hours - A course I built to teach chrome extension development ($9-20).