Method: Pathname#read_json

Defined in:
lib/pleasant_path/json/pathname.rb

#read_json(options = {}) ⇒ nil, ...

Reads the file indicated by the Pathname, and parses the contents as JSON. The returned result will be composed of only basic data types, e.g. nil, true, false, Numeric, String, Array, and Hash.

For information about options, see JSON.parse. By default, this method uses JSON.load_default_options plus create_additions: false.

Examples:

File.write("file.json", '{"key": "value"}')

Pathname.new("file.json").read_json  # == { "key" => "value" }

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

Returns:

  • (nil, true, false, Numeric, String, Symbol, Array, Hash)


23
24
25
# File 'lib/pleasant_path/json/pathname.rb', line 23

def read_json(options = {})
  JSON.load(self, nil, { create_additions: false, **options })
end