PHPackages                             rcs\_us/php-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. rcs\_us/php-json

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

rcs\_us/php-json
================

Wrapper for PHP's Native JSON encode/decode that provides very specific exceptions and details as to what is wrong with the JSON.

1.0.2(4y ago)065MITPHPPHP ^5.2 || ^7.0 || ^8.0

Since Feb 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/conrad10781/php-json)[ Packagist](https://packagist.org/packages/rcs_us/php-json)[ RSS](/packages/rcs-us-php-json/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

php-json
========

[](#php-json)

Wrapper for PHP's Native JSON encode/decode that provides very specific exceptions and details as to what is wrong with the JSON.

Install
-------

[](#install)

Install latest version using [composer](https://getcomposer.org/).

```
$ composer require rcs_us/php-json

```

Why?
----

[](#why)

Too often, we come across code that looks like:

```
// Decode JSON
$decoded_json = json_encode($json_to_encode);

// Act on decoded JSON
if ( $decoded_json->some_property == "some_value" ) {

}
```

The problem with this is no validation of the JSON *structure* is done. So if you're working with invalid JSON nothing will work as expected.

This library wraps the native json\_encode/json\_decode functionality, and additionally calls json\_last\_error(). If JSON\_ERROR\_NONE is returned ( see  ), then the value is returned, otherwise a corresponding Exception is thrown.

Several Exceptions are provided, which allows unlimited flexibility on your interaction with potentially invalid JSON.

To catch an Exception of any kind, catch \\RCS\\JsonException. For any type of encode related issue use \\RCS\\JsonEncodeException, for any type of decode related issue use \\RCS\\JsonDecodeException.

If you want to only catch a syntax error when decoding, use \\RCS\\JsonDecodeErrorSyntaxException. A list of all possible Exceptions are provided below. In short, all JSON error codes have their own exception, for both encoding and decoding.

You can very easily store this in a PSR-7 Middleware.

Details/Usage
-------------

[](#detailsusage)

```
string \RCS\Json::Encode ( mixed $value [, int $options = 0 [, int $depth = 512 ]] )
mixed \RCS\Json::Decode ( string $json [, bool $assoc = FALSE [, int $depth = 512 [, int $options = 0 ]]] )
```

Encode example

```
try {
    $encoded_json = \RCS\Json::Encode($json_to_encode);
} catch ( \RCS\JsonException $e ) {
    // ... Do what you want with the exception
}
```

Decode

```
try {
    $decoded_json = \RCS\Json::Decode($json_to_decode);
} catch ( \RCS\JsonException $e ) {
    // ... Do what you want with the exception
}
```

Possible Exceptions to catch

1. \\RCS\\JsonException ( extends \\Exception )
2. \\RCS\\JsonDecodeException ( extends \\RCS\\JsonException )
3. \\RCS\\JsonDecodeErrorDepthException ( extends \\RCS\\JsonDecodeException )
4. \\RCS\\JsonDecodeErrorStateMismatchException ( extends \\RCS\\JsonDecodeException )
5. \\RCS\\JsonDecodeErrorCtrlCharException ( extends \\RCS\\JsonDecodeException )
6. \\RCS\\JsonDecodeErrorSyntaxException ( extends \\RCS\\JsonDecodeException )
7. \\RCS\\JsonDecodeErrorUtf8Exception ( extends \\RCS\\JsonDecodeException )
8. \\RCS\\JsonDecodeErrorUnknownException ( extends \\RCS\\JsonDecodeException )
9. \\RCS\\JsonEncodeException ( extends \\RCS\\JsonException )
10. \\RCS\\JsonEncodeErrorDepthException ( extends \\RCS\\JsonEncodeException )
11. \\RCS\\JsonEncodeErrorStateMismatchException ( extends \\RCS\\JsonEncodeException )
12. \\RCS\\JsonEncodeErrorCtrlCharException ( extends \\RCS\\JsonEncodeException )
13. \\RCS\\JsonEncodeErrorSyntaxException ( extends \\RCS\\JsonEncodeException )
14. \\RCS\\JsonEncodeErrorUtf8Exception ( extends \\RCS\\JsonEncodeException )
15. \\RCS\\JsonEncodeErrorUnknownException ( extends \\RCS\\JsonEncodeException )

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1432 days

Total

2

Last Release

1575d ago

PHP version history (2 changes)1.0.0PHP ^5.2 || ^7.0

1.0.2PHP ^5.2 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/58820a9b8b9d37ea874dcaae1b92a4a7fd6c85946070546cd74c023abdd7afef?d=identicon)[conrad10781](/maintainers/conrad10781)

---

Top Contributors

[![conrad10781](https://avatars.githubusercontent.com/u/238705?v=4)](https://github.com/conrad10781 "conrad10781 (4 commits)")

---

Tags

phpjsonexception

### Embed Badge

![Health badge](/badges/rcs-us-php-json/health.svg)

```
[![Health](https://phpackages.com/badges/rcs-us-php-json/health.svg)](https://phpackages.com/packages/rcs-us-php-json)
```

###  Alternatives

[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
