Firsty, my references:
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/json/rdoc/JSON.html
http://apidock.com/ruby/JSON/pretty_generate
Second my versions:
$ gem list | egrep -nir "json"
json (1.8.0, 1.7.7, 1.5.5)
multi_json (1.7.7)
$ which ruby
...ruby-1.9.3-p448...
Finally, my code:
hash = YAML.load_file "my_yaml.yaml"
opts = {"indent"=>"\t", "space_before"=>" "}
json_pretty = JSON.pretty_generate(hash, opts)
The output, JSON.pretty_generate, does not seem to use the second argument, which should alter the output to the desired preferences.
The keys to the options hash must be symbols.
opts =
{
:indent => "\t",
:space_before => " "
}
json_pretty = JSON.pretty_generate( obj, opts )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With