PHPackages                             hampel/json - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. hampel/json

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

hampel/json
===========

A simple wrapper for json\_encode and json\_decode with exception based error handling

2.4.1(6y ago)097.2k↓24.3%9MITPHPPHP &gt;=5.5.0

Since Jun 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hampel/json)[ Packagist](https://packagist.org/packages/hampel/json)[ Docs](https://bitbucket.org/hampel/json)[ RSS](/packages/hampel-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (19)Used By (9)

JSON Wrapper
============

[](#json-wrapper)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b203a351abb5231f784e5a69565286a2da145036a9b8251229eccc528c108c58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616d70656c2f6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/json)[![Total Downloads](https://camo.githubusercontent.com/334fe68ecb5db20b3239f90ceee70204493691e19440b2a211085cab1f3a197f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616d70656c2f6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/json)[![Open Issues](https://camo.githubusercontent.com/cb1ac7ea0c55cc684c5cd5ce7f636277a3be2266aefbc856d761bd8b75de28fd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f68616d70656c2f6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/hampel/json/issues)[![License](https://camo.githubusercontent.com/52b4124635188aa4ff0eadcc212912bda98e6406eee74e04c00f9d53bf8932d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616d70656c2f6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/json)

A simple wrapper for `json_encode` and `json_decode` with exception based error handling

By [Simon Hampel](mailto:simon@hampelgroup.com)

**Note:** as of PHP v7.3 there is now a `JSON_THROW_ON_ERROR` option for both native commands which should effectively render this package obsolete.

Installation
------------

[](#installation)

To install using composer, run the following command:

`composer require hampel/json`

Note that there are three versions of this package, depending on the version of PHP you use:

- v2.1 supports PHP &gt;= v5.3.3
- v2.2 supports PHP &gt;= v5.4.0
- v2.3 supports PHP &gt;= v5.5.0

The three versions will be maintained in parallel

Usage
-----

[](#usage)

All parameters are the same as specified for the PHP functions json\_encode and json\_decode respectively.

The main difference that this class provides is that it throws exceptions when there are errors and translates the error codes into meaningful text for you automatically.

```
