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: