Class: Crack::JSON

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

Constant Summary

Class Method Summary collapse

Class Method Details

.parse(json) ⇒ Object



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

def self.parse(json)
  args = [unescape(convert_json_to_yaml(json))]
  args << nil if SafeYAML::MULTI_ARGUMENT_YAML_LOAD
  args << { :whitelisted_tags => ['!ruby/regexp'] }

  SafeYAML.load(*args)

rescue *parser_exceptions
  raise ParseError, "Invalid JSON string"
end

.parser_exceptionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/crack/json.rb', line 11

def self.parser_exceptions
  @parser_exceptions ||= begin
    exceptions = [ArgumentError]

    if const_defined?(:Psych)
      if Psych.const_defined?(:SyntaxError)
        exceptions << Psych::SyntaxError
      end
    end

    exceptions
  end
end