Reputation: 101
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.
Upvotes: 3
Views: 1298
Reputation: 76
The keys to the options hash must be symbols.
opts =
{
:indent => "\t",
:space_before => " "
}
json_pretty = JSON.pretty_generate( obj, opts )
Upvotes: 2
Reputation: 399
I think there is a bug in the json gem. I can't get :space_before to work either. Anyone know where to submit a bug against this?
Upvotes: 0