I am creating a hash in Ruby and want to write it to a JSON file, in the correct format.
Here is my code:
tempHash = { \"key_a\" => \"val_a\
Require the JSON library, and use to_json.
to_json
require 'json' tempHash = { "key_a" => "val_a", "key_b" => "val_b" } File.open("public/temp.json","w") do |f| f.write(tempHash.to_json) end
Your temp.json file now looks like:
{"key_a":"val_a","key_b":"val_b"}