Module: JSON

Defined in:
lib/rubocoin/core_extensions/json_ext.rb

Class Method Summary collapse

Class Method Details

.is_valid?(json) ⇒ Boolean

Check whether the given json is valid

Parameters:

  • json (String)

    the JSON to validate

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/rubocoin/core_extensions/json_ext.rb', line 8

def self.is_valid?(json)
  begin
    JSON.parse(json)
    true
  rescue JSON::ParserError
    false
  end
end