codekandis/json-error-handler

`codekandis/json-error-handler` is a library to handle JSON errors in an object oriented way.

3.0.0 2024-05-22 23:40 UTC

This package is auto-updated.

Last update: 2024-05-22 23:40:50 UTC


README

Version License Minimum PHP Version Code Coverage

With the JSON error handler you will be able to catch exceptions representing the last occurred JSON error containing the native error codes and error messages of PHP's JSON package.

Index

Installation

Install the latest version with

$ composer require codekandis/json-error-handler

How to use

The following example throws a JsonException with the error code of JsonErrorCodes::SYNTAX with the message of JsonErrorMessage::SYNTAX.

json_decode( '{"foobar":}' );
( new JsonErrorHandler() )->handle();

The error codes in JsonErrorCodes are equal to PHP's native JSON_ERROR constants. The error messages in JsonErrorMessages are equal to PHP's error messages of json_last_error_msg().