JsonValidator.php 603 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Serialize;
  7. /**
  8. * Validate JSON string
  9. */
  10. class JsonValidator
  11. {
  12. /**
  13. * Check if string is valid JSON string
  14. *
  15. * @param string $string
  16. * @return bool
  17. */
  18. public function isValid($string)
  19. {
  20. if ($string !== false && $string !== null && $string !== '') {
  21. json_decode($string);
  22. if (json_last_error() === JSON_ERROR_NONE) {
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. }