Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Created May 26, 2020 06:50
Show Gist options
  • Save adamcrampton/babe38d635d989c623a8300a43321087 to your computer and use it in GitHub Desktop.
Save adamcrampton/babe38d635d989c623a8300a43321087 to your computer and use it in GitHub Desktop.
Determine if PHP string is valid JSON
<?php
/**
* Checks if string is valid JSON.
*
* @param string $string
* @return bool
*/
public function jsonCheck($string)
{
return json_decode($string, true) === null && json_last_error() !== JSON_ERROR_NONE ? false : true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment