module JSON
def is_json?(string)
begin
parse(string).all?
rescue ParserError
false
end
end
end
class String
def is_json?
self[0..0] == '{'
end
end
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/LrgCCEl0BDs/12151