require 'json' my_json = { :array => [1, 2, 3, { :sample => "hash"} ], :foo => "bar" } puts JSON.pretty_generate(my_json) Which gets you... { "array": [ 1, 2, 3, { "sample": "hash" } ], "foo": "bar" }