3

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.

0

2 Answers 2

2

The keys to the options hash must be symbols.

opts =
{
   :indent => "\t",
   :space_before => " "
}
json_pretty = JSON.pretty_generate( obj, opts )
Sign up to request clarification or add additional context in comments.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.