Module: Overlord::JsonParser

Included in:
GoogleBase
Defined in:
lib/overlord/parse_json.rb

Instance Method Summary collapse

Instance Method Details

#parse_json(data) ⇒ Object

The various json parsers can choke on various json so try them all



5
6
7
# File 'lib/overlord/parse_json.rb', line 5

def parse_json(data)
  try_crack(data) || try_json(data) || try_active_json(data)
end

#try_active_json(data) ⇒ Object



23
24
25
26
27
28
# File 'lib/overlord/parse_json.rb', line 23

def try_active_json(data)
  ActiveSupport::JSON.decode(data)
rescue => ex
  #puts ex
  nil
end

#try_crack(data) ⇒ Object



9
10
11
12
13
14
# File 'lib/overlord/parse_json.rb', line 9

def try_crack(data)
  Crack::JSON.parse(data)
rescue => ex
  #puts ex
  nil
end

#try_json(data) ⇒ Object



16
17
18
19
20
21
# File 'lib/overlord/parse_json.rb', line 16

def try_json(data)
 JSON.parse(data)
rescue => ex
  #puts ex
  nil
end