PayPalValidationJsonValidator

Class JsonValidator.

Defined (1)

The class is defined in the following location(s).

/classes/lib/PayPal/Validation/JsonValidator.php  
  1. class JsonValidator 
  2.  
  3. /** 
  4. * Helper method for validating if string provided is a valid json. 
  5. * @param string $string String representation of Json object 
  6. * @param bool $silent Flag to not throw \InvalidArgumentException 
  7. * @return bool 
  8. */ 
  9. public static function validate($string, $silent = false) 
  10. @json_decode($string); 
  11. if (json_last_error() != JSON_ERROR_NONE) { 
  12. if ($string === '' || $string === null) { 
  13. return true; 
  14. if ($silent == false) { 
  15. //Throw an Exception for string or array 
  16. throw new \InvalidArgumentException("Invalid JSON String"); 
  17. return false; 
  18. return true;