- json_decode: documentation ( source)
- json_last_error: documentation ( source)
<?php
function isJson($string) {
$decoded = json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
if ( isJson(123) ) {
echo "valid JSON";
} else {
echo "not valid JSON";
}