Handling JSON Errors in PHP


Detect and handle errors in JSON encoding and decoding.

Source Code

$json = json_encode($data);
if (json_last_error() !== JSON_ERROR_NONE) {
    echo "JSON encoding error: " . json_last_error_msg();
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments