This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/lib/PayPal/Validation/JsonValidator.php
japatel 3c02790138 Updates to Sample Code
- Updated UI Presentation on samples
- Fixed Bugs
2014-11-02 18:22:35 -06:00

33 lines
775 B
PHP

<?php
namespace PayPal\Validation;
/**
* Class JsonValidator
*
* @package PayPal\Validation
*/
class JsonValidator
{
/**
* Helper method for validating if string provided is a valid json.
*
* @param string $string String representation of Json object
* @param bool $silent Flag to not throw \InvalidArgumentException
* @return bool
*/
public static function validate($string, $silent = false)
{
json_decode($string);
if (json_last_error() != JSON_ERROR_NONE) {
if ($silent == false) {
//Throw an Exception for string or array
throw new \InvalidArgumentException("Invalid JSON String");
}
return false;
}
return true;
}
}