Module: JSON

Defined in:
lib/ruby_cpu/core_ext/json/is_json.rb

Class Method Summary collapse

Class Method Details

.is_json?(text) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
# File 'lib/ruby_cpu/core_ext/json/is_json.rb', line 2

def self.is_json?(text)
  begin
    return false unless text.is_a?(String)
    !!JSON.parse(text)
  rescue JSON::ParserError
    false
  end 
end