-
Ruby 1.9.x: j and jj
j & jj the JSON conversant relatives of p & pp, i.e. they output JSON strings on one line or pretty print them over many lines with indentation respectively.
ruby-1.9.1-p378 > require 'JSON' => true ruby-1.9.1-p378 > obj = [{:foo => "bar", "baz" => [1,2,3,4,5]}] => [{:foo=>"bar", "baz"=>[1, 2, 3, 4, 5]}] ruby-1.9.1-p378 > j obj [{"foo":"bar","baz":[1,2,3,4,5]}] => nil ruby-1.9.1-p378 > jj obj [ { "foo": "bar", "baz": [ 1, 2, 3, 4, 5 ] } ] => nilNice. Although it would be nicer if when you did this:
ruby-1.9.1-p378 > j [{:first_10_natural_numbers => 0..9 }]You got this:
[{"first_10_natural_numbers":[0,1,2,3,4,5,6,7,8,9]}]Instead of this:
[{"first_10_natural_numbers":"0..9"}]Oh well.
Sun28Mar