https://github.com/codekandis/json-error-handler
`codekandis/json-error-handler` is a library to handle JSON errors in an object oriented way.
https://github.com/codekandis/json-error-handler
error handler json php
Last synced: 4 months ago
JSON representation
`codekandis/json-error-handler` is a library to handle JSON errors in an object oriented way.
- Host: GitHub
- URL: https://github.com/codekandis/json-error-handler
- Owner: codekandis
- License: mit
- Created: 2019-08-11T15:59:17.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-09-15T20:28:35.000Z (9 months ago)
- Last Synced: 2025-11-21T00:20:49.365Z (7 months ago)
- Topics: error, handler, json, php
- Language: PHP
- Homepage:
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# codekandis/json-error-handler
[![Version][xtlink-version-badge]][srclink-changelog]
[![License][xtlink-license-badge]][srclink-license]
[![Minimum PHP Version][xtlink-php-version-badge]][xtlink-php-net]
![Code Coverage][xtlink-code-coverage-badge]
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](#installation)
* [How to use](#how-to-use)
## Installation
Install the latest version with
```bash
$ composer require codekandis/json-error-handler
```
## How to use
The following example throws a [`JsonException`][srclink-json-exception] with the error code of [`JsonErrorCodes::SYNTAX`][srclink-json-error-codes] with the message of [`JsonErrorMessage::SYNTAX`][srclink-json-error-messages].
```php
json_decode( '{"foobar":}' );
( new JsonErrorHandler() )->handle();
```
The error codes in [`JsonErrorCodes`][srclink-json-error-codes] are equal to [PHP's native `JSON_ERROR`][xtlink-php-net-json-error-constant] constants. The error messages in [`JsonErrorMessages`][srclink-json-error-messages] are equal to [PHP's error messages of `json_last_error_msg()`][xtlink-php-net-json-last-error-msg].
[xtlink-version-badge]: https://img.shields.io/badge/version-3.0.0-blue.svg
[xtlink-license-badge]: https://img.shields.io/badge/license-MIT-yellow.svg
[xtlink-php-version-badge]: https://img.shields.io/badge/php-%3E%3D%208.2-8892BF.svg
[xtlink-code-coverage-badge]: https://img.shields.io/badge/coverage-100%25-green.svg
[xtlink-php-net]: https://php.net
[xtlink-php-net-json-error-constant]: https://www.php.net/manual/en/function.json-last-error.php#refsect1-function.json-last-error-returnvalues
[xtlink-php-net-json-last-error-msg]: https://www.php.net/manual/en/function.json-last-error-msg.php
[srclink-changelog]: ./CHANGELOG.md
[srclink-license]: ./LICENSE
[srclink-json-error-codes]: ./src/JsonErrorCodes.php
[srclink-json-error-messages]: ./src/JsonErrorMessages.php
[srclink-json-error-handler]: ./src/JsonErrorHandler.php
[srclink-json-exception]: ./src/JsonException.php