daverandom/exceptional-json

JSON encoding and decoding that throws exceptions on failure

Maintainers

👁 DaveRandom

Package info

github.com/DaveRandom/ExceptionalJSON

pkg:composer/daverandom/exceptional-json

Statistics

Installs: 1 433 736

Dependents: 15

Suggesters: 0

Stars: 31

Open Issues: 2

v1.0.4 2018-06-11 11:25 UTC

Requires

  • php: >=7.0

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT fed957142b4687b079495c80975666dd1a67d61d

  • Chris Wright

This package is auto-updated.

Last update: 2026-06-25 11:11:30 UTC


README

👁 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);