Skip to content
PHP JSON encoding and decoding that throws exceptions on failure
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.editorconfig
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
composer.json
phpunit.xml
readme.md

readme.md

Exceptional JSON

Build Status Scrutinizer Code Quality Code Coverage Packagist License

Thin wrapper around PHP's json_encode() and json_decode() functions, which throws exceptions when an operation fails.

Required PHP Version

  • PHP 7.0+

Installation

$ composer require daverandom/exceptional-json

Usage

Call the \ExceptionJSON\encode() and \ExceptionJSON\decode() functions in exactly the same way as you would with json_encode() and json_decode(). The only difference is that they will throw an exception if the operation fails.

Also defines json_try_encode() and json_try_decode() in the root namespace if they don't already exist, these are simply aliases of their namespaced counterparts.

$encoded = \ExceptionJSON\encode($data);
$decoded = \ExceptionJSON\decode($encoded);
You can’t perform that action at this time.