65536) { throw new InvalidArgumentException('JSON exceeds the 64 KiB limit.'); } if (!json_validate($json, 64)) { throw new InvalidArgumentException(json_last_error_msg()); } return $json; } foreach (['{"enabled":true}', '{"enabled":}', 'null'] as $fixture) { try { echo requireJsonDocument($fixture), PHP_EOL; } catch (InvalidArgumentException $error) { echo 'Rejected: ', $error->getMessage(), PHP_EOL; } }