Write_file_with_open.rb

This content was produced by an LLM and could include errors.

This script loads the JSON library, defines a sample Ruby hash, and then efficiently serializes that hash into JSON format, writing the resulting data structure to file.json.

require 'json'
#=> true

hash = {:key => 'value'}
#=> {key: "value"}

File.open('input/json/file.json', 'w') {|f| JSON.dump(hash, f)}
#=> #<File:input/json/file.json (closed)>

Ruby 4.0.3