Read_with_load.rb

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

このスクリプトはJSON読み込み方法の1つです。File.read で全文を文字列化してから JSON.load に渡し、{"key" => "value"} というハッシュへ変換します。load はIOオブジェクトも直接受け付けます(read_with_open.rb 参照)。

require 'json'
#=> true
JSON.load(File.read('input/json/file.json'))
#=> {"key" => "value"}

Ruby 4.0.6