pretty print snippets

How to pretty print JSON data with Ruby

Tagged ruby, json, pretty print  Languages ruby

This ugly one-liner will pretty print the JSON in countries.json, so that it's easier to read and edit:

cat db/seeds/countries.json | ruby -rubygems -e 'require "json";a=JSON.pretty_generate JSON.parse gets;File.open("db/seeds/countries.json", "w"){|f| f << a}'