Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // PHP 7.3+: throw on error try { $encoded = json_encode($data, JSON_THROW_ON_ERROR); $decoded = json_decode($input, true, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $e) { throw new RuntimeException("JSON error: " . $e->getMessage(), 0, $e); } // Old approach (PHP < 7.3) $decoded = json_decode($input, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new RuntimeException(json_last_error_msg()); }
Result
Open