Module: RbJSON5

Defined in:
lib/rb_json5.rb,
lib/rb_json5/parser.rb,
lib/rb_json5/version.rb,
lib/rb_json5/parse_error.rb,
lib/rb_json5/parser/misc.rb,
lib/rb_json5/parser/null.rb,
lib/rb_json5/parser/array.rb,
lib/rb_json5/parser/space.rb,
lib/rb_json5/parser/number.rb,
lib/rb_json5/parser/object.rb,
lib/rb_json5/parser/string.rb,
lib/rb_json5/parser/boolean.rb,
lib/rb_json5/escape_sequence.rb

Overview

JSON5 parser for Ruby

Defined Under Namespace

Classes: EscapeSequence, ParseError, Parser

Constant Summary collapse

VERSION =

Current version of RbJSON5

'0.3.0'

Class Method Summary collapse

Class Method Details

.load_file(filename, symbolize_names: false) ⇒ Object

Reads a JSON5 string from the given file and parses it into its Ruby data structure

Parameters:

  • filename (String)

    name of the given file

  • symbolize_names (Boolean) (defaults to: false)

    If set to true, converts names (keys) in a JSON5 object into Symbol

Returns:

  • (Object)

    Ruby data structure represented by the input

See Also:



43
44
45
# File 'lib/rb_json5.rb', line 43

def self.load_file(filename, symbolize_names: false)
  File.open(filename, 'r') { |io| parse(io, symbolize_names: symbolize_names) }
end

.parse(string_or_io, symbolize_names: false) ⇒ Object

Parses a JSON5 string into its Ruby data structure

Parameters:

  • string_or_io (String, #read)

    JSON5 string itself or object like IO containing JSON5 string

  • symbolize_names (Boolean) (defaults to: false)

    If set to true, converts names (keys) in a JSON5 object into Symbol

Returns:

  • (Object)

    Ruby data structure represented by the input

See Also:



29
30
31
# File 'lib/rb_json5.rb', line 29

def self.parse(string_or_io, symbolize_names: false)
  Parser.new.parse(string_or_io, symbolize_names)
end