instance method String#isJSON

View source on GitHub →

String#isJSON() → Boolean

Check if the string is valid JSON by the use of regular expressions. This security method is called internally.

Examples
"something".isJSON();
// -> false
"\"something\"".isJSON();
// -> true
"{ foo: 42 }".isJSON();
// -> false
"{ \"foo\": 42 }".isJSON();
// -> true