Class: Crack::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/crack/json.rb

Class Method Summary collapse

Class Method Details

.parse(json) ⇒ Object

Ruby < 2.6



25
26
27
28
29
30
31
32
# File 'lib/crack/json.rb', line 25

def self.parse(json)
  yaml = unescape(convert_json_to_yaml(json))
  YAML.safe_load(yaml, permitted_classes: [Regexp, Date, Time])
rescue *parser_exceptions
  raise ParseError, "Invalid JSON string"
rescue Psych::DisallowedClass
  yaml
end

.parser_exceptionsObject



11
12
13
# File 'lib/crack/json.rb', line 11

def self.parser_exceptions
  @parser_exceptions ||= [ArgumentError, Psych::SyntaxError]
end