if ($isJsonValid) {
echo "The JSON is valid.";
} else {
echo "The JSON is not valid.";
}
In the example above, the validateJson function is called to validate a JSON string stored in the $jsonString variable. The function uses json_decode to attempt decoding the JSON string. If the decoding is successful and there are no JSON errors, json_last_error() will return JSON_ERROR_NONE, indicating that the JSON is valid. The function returns a boolean value indicating the validity of the JSON. The result is stored in the $isJsonValid variable and is used to display an appropriate message to the user.
Note: Adjust the $jsonString variable to the actual JSON string you want to validate.