Validating JSON

The PHP json_decode function will return a strict null if the string passed into it is invalid json or it can’t parse it successfully. The method below can be used for testing json

$decodedJson = json_decode($json);
if($decodedJson !== null) {
	echo('$decodedJson is valid json!');
	echo('$decodedJson is invalid json');

Leave a Reply

Your email address will not be published. Required fields are marked *